From 9d78e1abcd518eba12afede48cbcba0bd18a2bbf Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Apr 2022 05:07:12 +0000 Subject: [PATCH 001/147] Auto-generated commit 43482f9c45ef889b0a27a96c6912a932bab06953 --- CONTRIBUTORS | 28 + LICENSE | 481 +++++++++ NOTICE | 1 + README.md | 520 ++++++++++ index.d.ts | 415 ++++++++ index.mjs | 4 + index.mjs.map | 1 + package.json | 46 + stats.html | 2689 +++++++++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 4185 insertions(+) create mode 100644 CONTRIBUTORS create mode 100644 LICENSE create mode 100644 NOTICE create mode 100644 README.md create mode 100644 index.d.ts create mode 100644 index.mjs create mode 100644 index.mjs.map create mode 100644 package.json create mode 100644 stats.html diff --git a/CONTRIBUTORS b/CONTRIBUTORS new file mode 100644 index 0000000..e5c896d --- /dev/null +++ b/CONTRIBUTORS @@ -0,0 +1,28 @@ +# This file is generated by tools/scripts/update_contributors. +# +# Contributors listed in alphabetical order. + +Ali Salesi +Athan Reines +Brendan Graetz +Bruno Fenzl +Christopher Dambamuromo +Dominik Moritz +Frank Kovacs +James +Jithin KS +Joey Reed +Joris Labie +Justin Dennison +Marcus +Matt Cochrane +Milan Raj +Momtchil Momtchev +Ognjen Jevremović +Philipp Burckhardt +Ricky Reusser +Ryan Seal +Seyyed Parsa Neshaei +Shraddheya Shendre +dorrin-sot <59933477+dorrin-sot@users.noreply.github.com> +rei2hu diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..fcc9934 --- /dev/null +++ b/LICENSE @@ -0,0 +1,481 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + + +Boost Software License - Version 1.0 - August 17th, 2003 + +Permission is hereby granted, free of charge, to any person or organization +obtaining a copy of the software and accompanying documentation covered by this +license (the "Software") to use, reproduce, display, distribute, execute, and +transmit the Software, and to prepare derivative works of the Software, and to +permit third-parties to whom the Software is furnished to do so, all subject to +the following: + +The copyright notices in the Software and this entire statement, including the +above license grant, this restriction and the following disclaimer, must be +included in all copies of the Software, in whole or in part, and all derivative +works of the Software, unless such copies or derivative works are solely in the +form of machine-executable object code generated by a source language processor. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE +COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES +OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + + + +DEPENDENCIES + +The library links against the following external libraries, which have their own +licenses: + +* OpenBLAS + +Copyright (c) 2011-2014, The OpenBLAS Project +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + 3. Neither the name of the OpenBLAS project nor the names of + its contributors may be used to endorse or promote products + derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE +GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF +THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +* Electron + +Copyright (c) 2013-2017 GitHub Inc. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + +* Boost + +Boost Software License - Version 1.0 - August 17th, 2003 + +Permission is hereby granted, free of charge, to any person or organization +obtaining a copy of the software and accompanying documentation covered by +this license (the "Software") to use, reproduce, display, distribute, +execute, and transmit the Software, and to prepare derivative works of the +Software, and to permit third-parties to whom the Software is furnished to +do so, all subject to the following: + +The copyright notices in the Software and this entire statement, including +the above license grant, this restriction and the following disclaimer, +must be included in all copies of the Software, in whole or in part, and +all derivative works of the Software, unless such copies or derivative +works are solely in the form of machine-executable object code generated by +a source language processor. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. + + +* Cephes + +Copyright (c) 1984-2000 Stephen L. Moshier + +Some software in this archive may be from the book _Methods and Programs for +Mathematical Functions_ (Prentice-Hall or Simon & Schuster International, 1989) +or from the Cephes Mathematical Library, a commercial product. In either event, +it is copyrighted by the author. What you see here may be used freely but it +comes with no support or guarantee. + +Stephen L. Moshier +moshier@na-net.ornl.gov + + + +ATTRIBUTION + +The library contains implementations from the following external libraries, +which have their own licenses: + +* FreeBSD + +Copyright (C) 1993-2004 by Sun Microsystems, Inc. All rights reserved. + +Developed at SunPro, a Sun Microsystems, Inc. business. +Permission to use, copy, modify, and distribute this +software is freely granted, provided that this notice +is preserved. + + +* FDLIBM + +Copyright (C) 2004 by Sun Microsystems, Inc. All rights reserved. + +Developed at SunPro, a Sun Microsystems, Inc. business. +Permission to use, copy, modify, and distribute this +software is freely granted, provided that this notice +is preserved. + + +* Go + +Copyright (c) 2009 The Go Authors. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following disclaimer +in the documentation and/or other materials provided with the +distribution. + * Neither the name of Google Inc. nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +* SLATEC Common Mathematical Library + +Public domain. + + +* ESLint + +Copyright JS Foundation and other contributors, https://js.foundation + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + + +* StatsFuns.jl + +Copyright (c) 2015: Dahua Lin. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + +* SpecialFunctions.jl + +The MIT License (MIT) + +Copyright (c) 2017 Jeff Bezanson, Stefan Karpinski, Viral B. Shah, and others: + +https://github.com/JuliaMath/SpecialFunctions.jl/graphs/contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + + +* MT19937 + +Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + 3. The names of its contributors may not be used to endorse or promote + products derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/NOTICE b/NOTICE new file mode 100644 index 0000000..10e6ba1 --- /dev/null +++ b/NOTICE @@ -0,0 +1 @@ +Copyright (c) 2016-2022 The Stdlib Authors. diff --git a/README.md b/README.md new file mode 100644 index 0000000..8d665af --- /dev/null +++ b/README.md @@ -0,0 +1,520 @@ + + +# reduceRightAsync + +[![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] + +> Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. + + + +
+ +
+ + + + + + + +
+ +## Usage + +```javascript +import reduceRightAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-reduce-right@esm/index.mjs'; +``` + +#### reduceRightAsync( collection, initial, \[options,] reducer, done ) + +Applies a `function` against an accumulator and each element in a `collection` and returns the accumulated result, iterating from right to left. + +```javascript +function reducer( acc, value, index, next ) { + setTimeout( onTimeout, value ); + function onTimeout() { + console.log( value ); + acc.sum += value; + next( null, acc ); + } +} + +function done( error, acc ) { + if ( error ) { + throw error; + } + console.log( acc.sum ); +} + +var arr = [ 1000, 2500, 3000 ]; +var acc = { + 'sum': 0 +}; +reduceRightAsync( arr, acc, reducer, done ); +/* + 3000 + 2500 + 1000 + 6500 +*/ +``` + +The `next` callback accepts two arguments: `error` and `accumulator`. The second argument to the `next` callback is passed as the first argument to the provided `reducer`. + + + +```javascript +function reducer( acc, value, index, next ) { + setTimeout( onTimeout, value ); + function onTimeout() { + next( null, acc ); + } +} + +function done( error, out ) { + if ( error ) { + throw error; + } + console.log( out === acc ); + // => true +} + +var arr = [ 1000, 2500, 3000 ]; +var acc = {}; + +reduceRightAsync( arr, acc, reducer, done ); +``` + +The function accepts the following `options`: + +- `limit`: the maximum number of pending invocations at any one time. If provided, the function sets `options.series=false`. Default: `infinity`. +- `series`: `boolean` indicating whether to sequentially invoke `reducer` for each `collection` element. If `true`, the function sets `options.limit=1`. Default: `true`. +- `thisArg`: the execution context for `reducer`. + +By default, all elements are processed **sequentially**, which means that the function **does** guarantee completion order. To process each `collection` element concurrently, set the `series` option to `false`. + +```javascript +function reducer( acc, value, index, next ) { + setTimeout( onTimeout, value ); + function onTimeout() { + console.log( value ); + acc.sum += value; + next( null, acc ); + } +} + +function done( error, acc ) { + if ( error ) { + throw error; + } + console.log( acc.sum ); +} + +var arr = [ 1000, 2500, 3000 ]; + +var acc = { + 'sum': 0 +}; + +var opts = { + 'series': false +}; + +reduceRightAsync( arr, acc, opts, reducer, done ); +/* => + 1000 + 2500 + 3000 + 6500 +*/ +``` + +To limit the maximum number of pending function invocations, set the `limit` option. + +```javascript +function reducer( acc, value, index, next ) { + setTimeout( onTimeout, value ); + function onTimeout() { + console.log( value ); + acc.sum += value; + next( null, acc ); + } +} + +function done( error, acc ) { + if ( error ) { + throw error; + } + console.log( acc.sum ); +} + +var arr = [ 1000, 2500, 3000 ]; + +var acc = { + 'sum': 0 +}; + +var opts = { + 'limit': 2 +}; + +reduceRightAsync( arr, acc, opts, reducer, done ); +/* => + 2500 + 3000 + 1000 + 6500 +*/ +``` + +To set the execution context of `reducer`, set the `thisArg` option. + +```javascript +function reducer( acc, value, index, next ) { + this.count += 1; + setTimeout( onTimeout, value ); + function onTimeout() { + acc.sum += value; + next( null, acc ); + } +} + +var arr = [ 1000, 2500, 3000 ]; + +var acc = { + 'sum': 0 +}; + +var context = { + 'count': 0 +}; + +var opts = { + 'thisArg': context +}; + +reduceRightAsync( arr, acc, opts, reducer, done ); + +function done( error, acc ) { + if ( error ) { + throw error; + } + console.log( acc.sum ); + // => 6500 + + console.log( context.count ); + // => 3 +} +``` + +When invoked, `reducer` is provided a maximum of five arguments: + +- `accumulator`: accumulated value. +- `value`: collection value. +- `index`: collection index. +- `collection`: the input `collection`. +- `next`: a callback which should be called once `reducer` has finished processing a collection `value`. + +The actual number of provided arguments depends on function `length`. If `reducer` accepts three arguments, `reducer` is provided `accumulator`, `value` and `next`. If `reducer` accepts four arguments, `reducer` is provided `accumulator`, `value`, `index`, and `next`. For every other `reducer` signature, `reducer` is provided all five arguments. + +```javascript +function reducer( acc, value, i, collection, next ) { + console.log( 'collection: %s. %d: %d', collection.join( ',' ), i, value ); + setTimeout( onTimeout, value ); + function onTimeout() { + console.log( value ); + acc.sum += value; + next( null, acc ); + } +} + +function done( error, acc ) { + if ( error ) { + throw error; + } + console.log( acc.sum ); +} + +var arr = [ 1000, 2500, 3000 ]; + +var acc = { + 'sum': 0 +}; + +reduceRightAsync( arr, acc, reducer, done ); +/* => + collection: 3000,2500,1000. 2: 3000 + collection: 3000,2500,1000. 1: 2500 + collection: 3000,2500,1000. 0: 1000 + 3000 + 2500 + 1000 + 6500 +*/ +``` + +#### reduceRightAsync.factory( \[options,] reducer ) + +Returns a `function` which invokes a function once for each element in a `collection`, iterating from right to left. + +```javascript +function reducer( acc, value, index, next ) { + setTimeout( onTimeout, value ); + function onTimeout() { + console.log( value ); + acc.sum += value; + next( null, acc ); + } +} + +function done( error, acc ) { + if ( error ) { + throw error; + } + console.log( acc.sum ); +} + +var f = reduceRightAsync.factory( reducer ); + +var arr1 = [ 1000, 2500, 3000 ]; + +var acc1 = { + 'sum': 0 +}; + +f( arr1, acc1, done ); +/* => + 3000 + 2500 + 1000 + 6500 +*/ + +var arr2 = [ 100, 250, 300 ]; + +var acc2 = { + 'sum': 0 +}; + +f( arr2, acc2, done ); +/* => + 300 + 250 + 100 + 650 +*/ +``` + +The function accepts the same `options` as `reduceRightAsync()`. + +
+ + + + + +
+ +## Notes + +- A `collection` may be either an [`Array`][mdn-array], [`Typed Array`][mdn-typed-array], or an array-like [`Object`][mdn-object] (excluding `strings` and `functions`). +- If a provided function calls the `next` callback with a truthy `error` argument, the function suspends execution and immediately calls the `done` callback for subsequent `error` handling. +- The function invokes the `done` callback with the `accumulator` provided as the second argument. If provided an empty `collection`, the function invokes the `done` callback with the `initial` value as the second argument. +- The function does **not** support dynamic `collection` resizing. +- The function does **not** skip `undefined` elements. +- When processing `collection` elements concurrently, **beware** of race conditions when updating an accumulator. This is especially true when an accumulator is a primitive (e.g., a `number`). In general, prefer `object` accumulators, as objects are passed by reference, not by value. +- **Neither** `reduceRightAsync` nor the function returned by the `factory` method **guarantee** asynchronous execution. To guarantee asynchrony, 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`). + +
+ + + + + +
+ +## Examples + + + +```html + + + + + + +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + +
+ +* * * + +## Notice + +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. + +For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. + +#### Community + +[![Chat][chat-image]][chat-url] + +--- + +## License + +See [LICENSE][stdlib-license]. + + +## Copyright + +Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. + +
+ + + + + + + + diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..9dc0658 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,415 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2021 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 2.0 + +/// + +import { Collection } from '@stdlib/types/object'; + +/** +* Interface defining function options. +*/ +interface Options { + /** + * The maximum number of pending invocations at any one time. + */ + limit?: number; + + /** + * Boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection (default: true). + */ + series?: boolean; + + /** + * Execution context. + */ + thisArg?: any; +} + +/** +* Callback function. +*/ +type Nullary = () => void; + +/** +* Callback function. +* +* @param error - encountered error or null +*/ +type Unary = ( error: Error | null ) => void; + +/** +* Callback function. +* +* @param error - encountered error or null +* @param accumulator - accumulated value +*/ +type Binary = ( error: Error | null, accumulator: any ) => void; + +/** +* Callback function. +* +* @param error - encountered error or null +* @param accumulator - accumulated value +*/ +type Callback = Nullary | Unary | Binary; + +/** +* Reducer function invoked for each element in a collection. +* +* @param accumulator - accumulated value +* @param value - collection value +* @param next - a callback to be invoked after processing a collection `value` +*/ +type TernaryReducer = ( accumulator: any, value: any, next: Callback ) => void; + +/** +* Reducer function invoked for each element in a collection. +* +* @param accumulator - accumulated value +* @param value - collection value +* @param index - collection index +* @param next - a callback to be invoked after processing a collection `value` +*/ +type QuaternaryReducer = ( accumulator: any, value: any, index: number, next: Callback ) => void; // tslint-disable-line max-line-length + +/** +* Reducer function invoked for each element in a collection. +* +* @param accumulator - accumulated value +* @param value - collection value +* @param index - collection index +* @param collection - the input collection +* @param next - a callback to be invoked after processing a collection `value` +*/ +type QuinaryReducer = ( accumulator: any, value: any, index: number, collection: Collection, next: Callback ) => void; // tslint-disable-line max-line-length + +/** +* Reducer function invoked for each element in a collection. +* +* @param accumulator - accumulated value +* @param value - collection value +* @param index - collection index +* @param collection - the input collection +* @param next - a callback to be invoked after processing a collection `value` +*/ +type Reducer = TernaryReducer | QuaternaryReducer | QuinaryReducer; + +/** +* Applies a function against an accumulator and each element in a collection and return the accumulated result. +* +* @param collection - input collection +* @param initial - initial value +* @param done - function to invoke upon completion +*/ +type FactoryFunction = ( collection: Collection, initial: any, done: Callback ) => void; // tslint-disable-line max-line-length + +/** +* Interface for `reduceRightAsync`. +*/ +interface ReduceRightAsync { + /** + * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. + * + * ## Notes + * + * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. + * - 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`). + * + * + * @param collection - input collection + * @param initial - initial value + * @param options - function options + * @param options.thisArg - execution context + * @param options.limit - maximum number of pending invocations at any one time + * @param 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 (default: true) + * @param reducer - function to invoke for each element in a collection + * @param done - function to invoke upon completion + * @throws must provide valid options + * + * @example + * var readFile = require( `@stdlib/fs/read-file` ); + * + * function done( error, acc ) { + * if ( error ) { + * throw error; + * } + * console.log( acc.count ); + * } + * + * function read( acc, file, next ) { + * var opts = { + * 'encoding': 'utf8' + * }; + * readFile( file, opts, onFile ); + * + * function onFile( error ) { + * if ( error ) { + * return next( null, acc ); + * } + * acc.count += 1; + * next( null, acc ); + * } + * } + * + * var files = [ + * './beep.js', + * './boop.js' + * ]; + * var acc = { + * 'count': 0 + * }; + * reduceRightAsync( files, acc, {}, read, done ); + */ + ( collection: Collection, initial: any, options: Options, reducer: Reducer, done: Callback ): void; // tslint-disable-line max-line-length + + /** + * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. + * + * ## Notes + * + * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. + * - 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`). + * + * + * @param collection - input collection + * @param initial - initial value + * @param options - function options + * @param options.thisArg - execution context + * @param options.limit - maximum number of pending invocations at any one time + * @param 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 (default: true) + * @param reducer - function to invoke for each element in a collection + * @param done - function to invoke upon completion + * @throws must provide valid options + * + * @example + * var readFile = require( `@stdlib/fs/read-file` ); + * + * function done( error, acc ) { + * if ( error ) { + * throw error; + * } + * console.log( acc.count ); + * } + * + * function read( acc, file, next ) { + * var opts = { + * 'encoding': 'utf8' + * }; + * readFile( file, opts, onFile ); + * + * function onFile( error ) { + * if ( error ) { + * return next( null, acc ); + * } + * acc.count += 1; + * next( null, acc ); + * } + * } + * + * var files = [ + * './beep.js', + * './boop.js' + * ]; + * var acc = { + * 'count': 0 + * }; + * reduceRightAsync( files, acc, read, done ); + */ + ( collection: Collection, initial: any, reducer: Reducer, done: Callback ): void; // tslint-disable-line max-line-length + + /** + * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. + * + * ## Notes + * + * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. + * - 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`). + * + * + * @param options - function options + * @param options.thisArg - execution context + * @param options.limit - maximum number of pending invocations at any one time + * @param 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 (default: true) + * @param reducer - function to invoke for each element in a collection + * @throws must provide valid options + * @returns function which invokes the provided function once for each element in a collection + * + * @example + * var readFile = require( `@stdlib/fs/read-file` ); + * + * function read( acc, file, next ) { + * var opts = { + * 'encoding': 'utf8' + * }; + * readFile( file, opts, onFile ); + * + * function onFile( error, data ) { + * if ( error ) { + * return next( null, acc ); + * } + * acc.count += 1; + * next( null, acc ); + * } + * } + * + * var opts = { + * 'series': false + * }; + * + * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: + * var reduceRightAsync = factory( opts, read ); + * + * // Create a collection over which to iterate: + * var files = [ + * './beep.js', + * './boop.js' + * ]; + * + * // Define a callback which handles errors: + * function done( error, acc ) { + * if ( error ) { + * throw error; + * } + * console.log( acc.count ); + * } + * + * // Run `read` for each element in `files`: + * var acc = { + * 'count': 0 + * }; + * reduceRightAsync( files, acc, done ); + */ + factory( options: Options, reducer: Reducer ): FactoryFunction; + + /** + * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. + * + * ## Notes + * + * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. + * - 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`). + * + * + * @param reducer - function to invoke for each element in a collection + * @returns function which invokes the provided function once for each element in a collection + * + * @example + * var readFile = require( `@stdlib/fs/read-file` ); + * + * function read( acc, file, next ) { + * var opts = { + * 'encoding': 'utf8' + * }; + * readFile( file, opts, onFile ); + * + * function onFile( error, data ) { + * if ( error ) { + * return next( null, acc ); + * } + * acc.count += 1; + * next( null, acc ); + * } + * } + * + * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: + * var reduceRightAsync = factory( read ); + * + * // Create a collection over which to iterate: + * var files = [ + * './beep.js', + * './boop.js' + * ]; + * + * // Define a callback which handles errors: + * function done( error, acc ) { + * if ( error ) { + * throw error; + * } + * console.log( acc.count ); + * } + * + * // Run `read` for each element in `files`: + * var acc = { + * 'count': 0 + * }; + * reduceRightAsync( files, acc, done ); + */ + factory( reducer: Reducer ): FactoryFunction; +} + +/** +* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. +* +* ## Notes +* +* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. +* - 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`). +* +* +* @param collection - input collection +* @param initial - initial value +* @param options - function options +* @param options.thisArg - execution context +* @param options.limit - maximum number of pending invocations at any one time +* @param 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 (default: true) +* @param reducer - function to invoke for each element in a collection +* @param done - function to invoke upon completion +* @throws must provide valid options +* +* @example +* var readFile = require( `@stdlib/fs/read-file` ); +* +* function done( error, acc ) { +* if ( error ) { +* throw error; +* } +* console.log( acc.count ); +* } +* +* function read( acc, file, next ) { +* var opts = { +* 'encoding': 'utf8' +* }; +* readFile( file, opts, onFile ); +* +* function onFile( error ) { +* if ( error ) { +* return next( null, acc ); +* } +* acc.count += 1; +* next( null, acc ); +* } +* } +* +* var files = [ +* './beep.js', +* './boop.js' +* ]; +* var acc = { +* 'count': 0 +* }; +* reduceRightAsync( files, acc, read, done ); +*/ +declare var reduceRightAsync: ReduceRightAsync; + + +// EXPORTS // + +export = reduceRightAsync; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..c2edb56 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";function a(e){if(e.__esModule)return e;var t=Object.defineProperty({},"__esModule",{value:!0});return Object.keys(e).forEach((function(r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})})),t}var c=o,m=s,f=l.isPrimitive,d=u.isPrimitive,h=n;var p=function(e,t){return c(t)?(m(t,"thisArg")&&(e.thisArg=t.thisArg),m(t,"series")&&(e.series=t.series,!f(e.series))?new TypeError(h("invalid option. `%s` option must be a boolean. Option: `%s`.","series",e.series)):m(t,"limit")&&(e.limit=t.limit,!d(e.limit))?new TypeError(h("invalid option. `%s` option must be a positive integer. Option: `%s`.","limit",e.limit)):null):new TypeError(h("invalid argument. Options argument must be an object. Value: `%s`.",t))},g="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function v(){throw new Error("setTimeout has not been defined")}function w(){throw new Error("clearTimeout has not been defined")}var b=v,j=w;function y(e){if(b===setTimeout)return setTimeout(e,0);if((b===v||!b)&&setTimeout)return b=setTimeout,setTimeout(e,0);try{return b(e,0)}catch(t){try{return b.call(null,e,0)}catch(t){return b.call(this,e,0)}}}"function"==typeof g.setTimeout&&(b=setTimeout),"function"==typeof g.clearTimeout&&(j=clearTimeout);var T,x=[],E=!1,O=-1;function A(){E&&T&&(E=!1,T.length?x=T.concat(x):O=-1,x.length&&_())}function _(){if(!E){var e=y(A);E=!0;for(var t=x.length;t;){for(T=x,x=[];++O1)for(var r=1;r0&&m();function m(){function i(e,r){if(!s){if(e)return s=!0,f(e);B("Accumulator: %s",JSON.stringify(r)),t=r,f()}}B("Collection element %d: %s.",a-=1,JSON.stringify(e[a])),3===n.length?n.call(r.thisArg,t,e[a],i):4===n.length?n.call(r.thisArg,t,e[a],a,i):n.call(r.thisArg,t,e[a],a,e,i)}function f(e){return e?(B("Encountered an error: %s",e.message),i(e)):(B("Processed %d of %d collection elements.",o+=1,u),a>0?m():o===u?(B("Finished processing a collection."),i(null,t)):void 0)}};var U=function(e,t){var r,n,i;if(r={},arguments.length>1){if(n=Q(r,e))throw n;i=t}else i=e;if(!G(i))throw new TypeError(I("invalid argument. Last argument must be a function. Value: `%s`.",i));return void 0===r.series&&void 0===r.limit&&(r.series=!0),r.series?r.limit=1:r.limit||(r.limit=K),o;function o(e,t,n){if(!H(e))throw new TypeError(I("invalid argument. First argument must be a collection. Value: `%s`.",e));if(!G(n))throw new TypeError(I("invalid argument. Last argument must be a function. Value: `%s`.",n));return R(e,t,r,i,(function(e,t){if(e)return n(e);n(null,t)}))}},W=U;var X=function(e,t,r,n,i){if(arguments.length<5)return W(r)(e,t,n);W(r,n)(e,t,i)},Y=U;e(X,"factory",Y);var Z=X;export{Z as default,Y as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..19f4dbb --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../node_modules/debug/src/index.js","../lib/limit.js","../lib/factory.js","../lib/reduce_right.js","../lib/index.js"],"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 * Detect Electron renderer process, which is node, but we should\n * treat as a browser.\n */\n\nif (typeof process !== 'undefined' && process.type === 'renderer') {\n module.exports = require('./browser.js');\n} else {\n module.exports = require('./node.js');\n}\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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\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 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 to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\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 === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, 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 ( !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, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\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* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\n* @param {Collection} collection - input collection\n* @param {*} initial - initial value\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=true] - 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} fcn - 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} 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, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nmodule.exports = reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' );\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar reduceRightAsync = require( './reduce_right.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( reduceRightAsync, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = reduceRightAsync;\n"],"names":["isObject","require$$0","hasOwnProp","require$$1","isBoolean","require$$2","isPrimitive","isPositiveInteger","require$$3","format","require$$4","validate_1","opts","options","thisArg","series","TypeError","limit","module","exports","process","type","require","debug","logger","isFunction","isCollection","PINF","validate","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory_1","err","f","arguments","reduceRightAsync","initial","factory","lib"],"mappings":";;2jCAsBA,IAAIA,EAAWC,EACXC,EAAaC,EACbC,EAAYC,EAAuCC,YACnDC,EAAoBC,EAAgDF,YACpEG,EAASC,EAqDb,IAAAC,EAzBA,SAAmBC,EAAMC,GACxB,OAAMb,EAAUa,IAGXX,EAAYW,EAAS,aACzBD,EAAKE,QAAUD,EAAQC,SAEnBZ,EAAYW,EAAS,YACzBD,EAAKG,OAASF,EAAQE,QAChBX,EAAWQ,EAAKG,SACd,IAAIC,UAAWP,EAAQ,+DAAgE,SAAUG,EAAKG,SAG1Gb,EAAYW,EAAS,WACzBD,EAAKK,MAAQJ,EAAQI,OACfV,EAAmBK,EAAKK,QACtB,IAAID,UAAWP,EAAQ,wEAAyE,QAASG,EAAKK,QAGhH,MAjBC,IAAID,UAAWP,EAAQ,qEAAsEI,27DClDpGK,OAAOC,aADc,IAAZC,GAA4C,aAAjBA,EAAQC,KAC3BC,QAAQ,gBAERA,QAAQ,iBCmBvBC,oCAAQC,CAAQ,4BAkHpB,ICvHIC,EAAaxB,EACbyB,EAAevB,EACfM,EAASJ,EACTsB,EAAOnB,EACPoB,EAAWlB,EACXO,EDkBJ,SAAgBY,EAAYC,EAAKlB,EAAMmB,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMP,EAAWU,OACjBhB,EAAO,wBAAyBa,GAEnB,IAARA,EAEJ,OADAb,EAAO,qCACAS,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMxB,EAAKK,MACTmB,EAEAxB,EAAKK,MAEZM,EAAO,wBAAyBY,GAChCZ,EAAO,0BAA2BQ,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdnB,EAAO,kBAAmBsB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,KA3BDrB,EAAO,6BADPc,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAMnC,EAAKE,QAASgB,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAMnC,EAAKE,QAASgB,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAMnC,EAAKE,QAASgB,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,GAgCnE,SAASG,EAAMF,GACd,OAAKA,GACJnB,EAAO,2BAA4BmB,EAAMM,SAClChB,EAAMU,KAGdnB,EAAO,0CADPU,GAAS,EACgDG,GACpDC,EAAM,EACHG,IAEHP,IAAUG,GACdb,EAAO,qCACAS,EAAM,KAAMF,SAFpB,KCiCF,IAAAmB,EApEA,SAAkBpC,EAASkB,GAC1B,IAAInB,EACAsC,EACAC,EAGJ,GADAvC,EAAO,GACFwC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMtB,EAAUhB,EAAMC,GAErB,MAAMqC,EAEPC,EAAIpB,OAEJoB,EAAItC,EAEL,IAAMY,EAAY0B,GACjB,MAAM,IAAInC,UAAWP,EAAQ,mEAAoE0C,IAUlG,YARqB,IAAhBvC,EAAKG,aAAoC,IAAfH,EAAKK,QACnCL,EAAKG,QAAS,GAEVH,EAAKG,OACTH,EAAKK,MAAQ,EACDL,EAAKK,QACjBL,EAAKK,MAAQU,GAEP0B,EAaP,SAASA,EAAkBxB,EAAYyB,EAAStB,GAC/C,IAAMN,EAAcG,GACnB,MAAM,IAAIb,UAAWP,EAAQ,sEAAuEoB,IAErG,IAAMJ,EAAYO,GACjB,MAAM,IAAIhB,UAAWP,EAAQ,mEAAoEuB,IAElG,OAAOf,EAAOY,EAAYyB,EAAS1C,EAAMuC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,QCtIXyB,EAAUtD,EAyEd,IC9BAoD,EDoBA,SAA2BxB,EAAYyB,EAASzC,EAASkB,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOgB,EAAS1C,EAAT0C,CAAoB1B,EAAYyB,EAASvB,GAEjDwB,EAAS1C,EAASkB,EAAlBwB,CAAyB1B,EAAYyB,EAAStB,ICvB/CuB,EAAAlD,EAFAJ,EAOAoD,EAAA,UAAAE,GAKA,IAAAC,EAAAH"} \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..f82dc4d --- /dev/null +++ b/package.json @@ -0,0 +1,46 @@ +{ + "name": "@stdlib/utils-async-reduce-right", + "version": "0.0.0", + "description": "Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.", + "license": "Apache-2.0", + "type": "module", + "main": "./index.mjs", + "homepage": "https://stdlib.io", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/utils-async-reduce-right.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "keywords": [ + "stdlib", + "stdutils", + "stdutil", + "utilities", + "utility", + "utils", + "util", + "asynchronous", + "async", + "reduce", + "right", + "reduceright", + "reducer", + "reduction", + "array.reduce", + "array.reduceright", + "iterate", + "aggregate", + "accumulator", + "accumulate", + "accumulation", + "collection", + "array", + "array-like" + ], + "funding": { + "type": "patreon", + "url": "https://www.patreon.com/athan" + } +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..58f07a4 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + From 873aa09dc2418572cad0a33d13d5489811c7e3ce Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 30 Jun 2022 22:03:00 +0000 Subject: [PATCH 002/147] Transform error messages --- lib/factory.js | 8 ++++---- lib/validate.js | 8 ++++---- package.json | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index a627d69..6d67be2 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -22,7 +22,7 @@ var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var PINF = require( '@stdlib/constants-float64-pinf' ); var validate = require( './validate.js' ); var limit = require( './limit.js' ); @@ -110,7 +110,7 @@ function factory( options, fcn ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '0id43', f ) ); } if ( opts.series === void 0 && opts.limit === void 0 ) { opts.series = true; @@ -135,10 +135,10 @@ function factory( options, fcn ) { */ function reduceRightAsync( collection, initial, done ) { if ( !isCollection( collection ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a collection. Value: `%s`.', collection ) ); + throw new TypeError( format( '0idBO', collection ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '0id43', done ) ); } return limit( collection, initial, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index 9ba927e..6292663 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,7 +54,7 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0id2h', options ) ); } if ( hasOwnProp( options, 'thisArg' ) ) { opts.thisArg = options.thisArg; @@ -62,13 +62,13 @@ function validate( opts, options ) { if ( hasOwnProp( options, 'series' ) ) { opts.series = options.series; if ( !isBoolean( opts.series ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'series', opts.series ) ); + return new TypeError( format( '0id30', 'series', opts.series ) ); } } if ( hasOwnProp( options, 'limit' ) ) { opts.limit = options.limit; if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'limit', opts.limit ) ); + return new TypeError( format( '0id3b', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index fb48f96..005e6d8 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-plain-object": "^0.0.x", "@stdlib/assert-is-positive-integer": "^0.0.x", "@stdlib/constants-float64-pinf": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x", "debug": "^2.6.9" From ff630cc1acf53651f48d3c414d0728b2da4c13a2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 03:14:50 +0000 Subject: [PATCH 003/147] Remove files --- index.d.ts | 415 -------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 3109 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 9dc0658..0000000 --- a/index.d.ts +++ /dev/null @@ -1,415 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Collection } from '@stdlib/types/object'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * The maximum number of pending invocations at any one time. - */ - limit?: number; - - /** - * Boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection (default: true). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback function. -*/ -type Nullary = () => void; - -/** -* Callback function. -* -* @param error - encountered error or null -*/ -type Unary = ( error: Error | null ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Binary = ( error: Error | null, accumulator: any ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param next - a callback to be invoked after processing a collection `value` -*/ -type TernaryReducer = ( accumulator: any, value: any, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuaternaryReducer = ( accumulator: any, value: any, index: number, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuinaryReducer = ( accumulator: any, value: any, index: number, collection: Collection, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type Reducer = TernaryReducer | QuaternaryReducer | QuinaryReducer; - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result. -* -* @param collection - input collection -* @param initial - initial value -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( collection: Collection, initial: any, done: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Interface for `reduceRightAsync`. -*/ -interface ReduceRightAsync { - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, {}, read, done ); - */ - ( collection: Collection, initial: any, options: Options, reducer: Reducer, done: Callback ): void; // tslint-disable-line max-line-length - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, read, done ); - */ - ( collection: Collection, initial: any, reducer: Reducer, done: Callback ): void; // tslint-disable-line max-line-length - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @throws must provide valid options - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var opts = { - * 'series': false - * }; - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( opts, read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( options: Options, reducer: Reducer ): FactoryFunction; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param reducer - function to invoke for each element in a collection - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( reducer: Reducer ): FactoryFunction; -} - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param collection - input collection -* @param initial - initial value -* @param options - function options -* @param options.thisArg - execution context -* @param options.limit - maximum number of pending invocations at any one time -* @param 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 (default: true) -* @param reducer - function to invoke for each element in a collection -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( `@stdlib/fs/read-file` ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -declare var reduceRightAsync: ReduceRightAsync; - - -// EXPORTS // - -export = reduceRightAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index c2edb56..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";function a(e){if(e.__esModule)return e;var t=Object.defineProperty({},"__esModule",{value:!0});return Object.keys(e).forEach((function(r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})})),t}var c=o,m=s,f=l.isPrimitive,d=u.isPrimitive,h=n;var p=function(e,t){return c(t)?(m(t,"thisArg")&&(e.thisArg=t.thisArg),m(t,"series")&&(e.series=t.series,!f(e.series))?new TypeError(h("invalid option. `%s` option must be a boolean. Option: `%s`.","series",e.series)):m(t,"limit")&&(e.limit=t.limit,!d(e.limit))?new TypeError(h("invalid option. `%s` option must be a positive integer. Option: `%s`.","limit",e.limit)):null):new TypeError(h("invalid argument. Options argument must be an object. Value: `%s`.",t))},g="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function v(){throw new Error("setTimeout has not been defined")}function w(){throw new Error("clearTimeout has not been defined")}var b=v,j=w;function y(e){if(b===setTimeout)return setTimeout(e,0);if((b===v||!b)&&setTimeout)return b=setTimeout,setTimeout(e,0);try{return b(e,0)}catch(t){try{return b.call(null,e,0)}catch(t){return b.call(this,e,0)}}}"function"==typeof g.setTimeout&&(b=setTimeout),"function"==typeof g.clearTimeout&&(j=clearTimeout);var T,x=[],E=!1,O=-1;function A(){E&&T&&(E=!1,T.length?x=T.concat(x):O=-1,x.length&&_())}function _(){if(!E){var e=y(A);E=!0;for(var t=x.length;t;){for(T=x,x=[];++O1)for(var r=1;r0&&m();function m(){function i(e,r){if(!s){if(e)return s=!0,f(e);B("Accumulator: %s",JSON.stringify(r)),t=r,f()}}B("Collection element %d: %s.",a-=1,JSON.stringify(e[a])),3===n.length?n.call(r.thisArg,t,e[a],i):4===n.length?n.call(r.thisArg,t,e[a],a,i):n.call(r.thisArg,t,e[a],a,e,i)}function f(e){return e?(B("Encountered an error: %s",e.message),i(e)):(B("Processed %d of %d collection elements.",o+=1,u),a>0?m():o===u?(B("Finished processing a collection."),i(null,t)):void 0)}};var U=function(e,t){var r,n,i;if(r={},arguments.length>1){if(n=Q(r,e))throw n;i=t}else i=e;if(!G(i))throw new TypeError(I("invalid argument. Last argument must be a function. Value: `%s`.",i));return void 0===r.series&&void 0===r.limit&&(r.series=!0),r.series?r.limit=1:r.limit||(r.limit=K),o;function o(e,t,n){if(!H(e))throw new TypeError(I("invalid argument. First argument must be a collection. Value: `%s`.",e));if(!G(n))throw new TypeError(I("invalid argument. Last argument must be a function. Value: `%s`.",n));return R(e,t,r,i,(function(e,t){if(e)return n(e);n(null,t)}))}},W=U;var X=function(e,t,r,n,i){if(arguments.length<5)return W(r)(e,t,n);W(r,n)(e,t,i)},Y=U;e(X,"factory",Y);var Z=X;export{Z as default,Y as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 19f4dbb..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../node_modules/debug/src/index.js","../lib/limit.js","../lib/factory.js","../lib/reduce_right.js","../lib/index.js"],"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 * Detect Electron renderer process, which is node, but we should\n * treat as a browser.\n */\n\nif (typeof process !== 'undefined' && process.type === 'renderer') {\n module.exports = require('./browser.js');\n} else {\n module.exports = require('./node.js');\n}\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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\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 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 to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\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 === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, 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 ( !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, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\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* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\n* @param {Collection} collection - input collection\n* @param {*} initial - initial value\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=true] - 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} fcn - 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} 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, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nmodule.exports = reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' );\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar reduceRightAsync = require( './reduce_right.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( reduceRightAsync, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = reduceRightAsync;\n"],"names":["isObject","require$$0","hasOwnProp","require$$1","isBoolean","require$$2","isPrimitive","isPositiveInteger","require$$3","format","require$$4","validate_1","opts","options","thisArg","series","TypeError","limit","module","exports","process","type","require","debug","logger","isFunction","isCollection","PINF","validate","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory_1","err","f","arguments","reduceRightAsync","initial","factory","lib"],"mappings":";;2jCAsBA,IAAIA,EAAWC,EACXC,EAAaC,EACbC,EAAYC,EAAuCC,YACnDC,EAAoBC,EAAgDF,YACpEG,EAASC,EAqDb,IAAAC,EAzBA,SAAmBC,EAAMC,GACxB,OAAMb,EAAUa,IAGXX,EAAYW,EAAS,aACzBD,EAAKE,QAAUD,EAAQC,SAEnBZ,EAAYW,EAAS,YACzBD,EAAKG,OAASF,EAAQE,QAChBX,EAAWQ,EAAKG,SACd,IAAIC,UAAWP,EAAQ,+DAAgE,SAAUG,EAAKG,SAG1Gb,EAAYW,EAAS,WACzBD,EAAKK,MAAQJ,EAAQI,OACfV,EAAmBK,EAAKK,QACtB,IAAID,UAAWP,EAAQ,wEAAyE,QAASG,EAAKK,QAGhH,MAjBC,IAAID,UAAWP,EAAQ,qEAAsEI,27DClDpGK,OAAOC,aADc,IAAZC,GAA4C,aAAjBA,EAAQC,KAC3BC,QAAQ,gBAERA,QAAQ,iBCmBvBC,oCAAQC,CAAQ,4BAkHpB,ICvHIC,EAAaxB,EACbyB,EAAevB,EACfM,EAASJ,EACTsB,EAAOnB,EACPoB,EAAWlB,EACXO,EDkBJ,SAAgBY,EAAYC,EAAKlB,EAAMmB,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMP,EAAWU,OACjBhB,EAAO,wBAAyBa,GAEnB,IAARA,EAEJ,OADAb,EAAO,qCACAS,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMxB,EAAKK,MACTmB,EAEAxB,EAAKK,MAEZM,EAAO,wBAAyBY,GAChCZ,EAAO,0BAA2BQ,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdnB,EAAO,kBAAmBsB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,KA3BDrB,EAAO,6BADPc,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAMnC,EAAKE,QAASgB,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAMnC,EAAKE,QAASgB,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAMnC,EAAKE,QAASgB,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,GAgCnE,SAASG,EAAMF,GACd,OAAKA,GACJnB,EAAO,2BAA4BmB,EAAMM,SAClChB,EAAMU,KAGdnB,EAAO,0CADPU,GAAS,EACgDG,GACpDC,EAAM,EACHG,IAEHP,IAAUG,GACdb,EAAO,qCACAS,EAAM,KAAMF,SAFpB,KCiCF,IAAAmB,EApEA,SAAkBpC,EAASkB,GAC1B,IAAInB,EACAsC,EACAC,EAGJ,GADAvC,EAAO,GACFwC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMtB,EAAUhB,EAAMC,GAErB,MAAMqC,EAEPC,EAAIpB,OAEJoB,EAAItC,EAEL,IAAMY,EAAY0B,GACjB,MAAM,IAAInC,UAAWP,EAAQ,mEAAoE0C,IAUlG,YARqB,IAAhBvC,EAAKG,aAAoC,IAAfH,EAAKK,QACnCL,EAAKG,QAAS,GAEVH,EAAKG,OACTH,EAAKK,MAAQ,EACDL,EAAKK,QACjBL,EAAKK,MAAQU,GAEP0B,EAaP,SAASA,EAAkBxB,EAAYyB,EAAStB,GAC/C,IAAMN,EAAcG,GACnB,MAAM,IAAIb,UAAWP,EAAQ,sEAAuEoB,IAErG,IAAMJ,EAAYO,GACjB,MAAM,IAAIhB,UAAWP,EAAQ,mEAAoEuB,IAElG,OAAOf,EAAOY,EAAYyB,EAAS1C,EAAMuC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,QCtIXyB,EAAUtD,EAyEd,IC9BAoD,EDoBA,SAA2BxB,EAAYyB,EAASzC,EAASkB,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOgB,EAAS1C,EAAT0C,CAAoB1B,EAAYyB,EAASvB,GAEjDwB,EAAS1C,EAASkB,EAAlBwB,CAAyB1B,EAAYyB,EAAStB,ICvB/CuB,EAAAlD,EAFAJ,EAOAoD,EAAA,UAAAE,GAKA,IAAAC,EAAAH"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 58f07a4..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From ab96e2ac09200c04597301ff8aa58e22cd8acc83 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 03:15:38 +0000 Subject: [PATCH 004/147] Auto-generated commit --- .editorconfig | 181 -- .eslintrc.js | 1 - .gitattributes | 33 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 681 ------ .github/workflows/publish.yml | 157 -- .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 -- .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 -- .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 ---- README.md | 47 +- benchmark/benchmark.factory.js | 73 - benchmark/benchmark.js | 160 -- branches.md | 53 - docs/repl.txt | 224 -- docs/types/test.ts | 166 -- examples/index.js | 55 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 165 -- lib/index.js | 77 - lib/limit.js | 142 -- lib/reduce_right.js | 96 - lib/validate.js | 80 - package.json | 64 +- stats.html | 2689 +++++++++++++++++++++ test/test.factory.js | 1095 --------- test/test.js | 38 - test/test.reduce_right.js | 1035 -------- test/test.validate.js | 181 -- 44 files changed, 2720 insertions(+), 6576 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/limit.js delete mode 100644 lib/reduce_right.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.reduce_right.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 7212d81..0000000 --- a/.gitattributes +++ /dev/null @@ -1,33 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 5ee3432..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-06-30T22:02:30.002Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1e08946..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 29bf533..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a7a7f51..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.9.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 663f5df..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 39b1613..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 7ca169c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 8 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "::set-output name=package_name::$name" - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "::set-output name=data::$data" - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v2 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v2 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 128c22e..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,681 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the repository: - push: - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs rm -rf - - git add -A - git commit -m "Remove files" - - git merge -s recursive -X theirs origin/production --allow-unrelated-histories - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch or create new branch tag: - - name: 'Push changes to `deno` branch or create new branch tag' - run: | - SLUG=${{ github.repository }} - VERSION=$(echo ${{ github.ref }} | sed -E -n 's/refs\/tags\/?(v[0-9]+.[0-9]+.[0-9]+).*/\1/p') - if [ -z "$VERSION" ]; then - echo "Workflow job was not triggered by a new tag...." - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - else - echo "Workflow job was triggered by a new tag: $VERSION" - echo "Creating new bundle branch tag of the form $VERSION-deno" - git tag -a $VERSION-deno -m "$VERSION-deno" - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" $VERSION-deno - fi - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs rm -rf - - git add -A - git commit -m "Remove files" - - git merge -s recursive -X theirs origin/production --allow-unrelated-histories - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "::set-output name=alias::${alias}" - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -447,7 +446,7 @@ reduceRightAsync( files, acc, read, done ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -515,11 +514,11 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right +[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right/tree/esm -[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce +[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/tree/esm diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 46d8b83..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var reduceRightAsync; - var arr; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - reduceRightAsync = factory( onItem ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - var acc; - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 6ad0714..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var reduceRightAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=false', function benchmark( b ) { - var opts; - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'series': false - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var arr; - var len; - var acc; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'limit': 3 - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 2aded98..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right" -click B href "https://github.com/stdlib-js/utils-async-reduce-right/tree/main" -click C href "https://github.com/stdlib-js/utils-async-reduce-right/tree/production" -click D href "https://github.com/stdlib-js/utils-async-reduce-right/tree/esm" -click E href "https://github.com/stdlib-js/utils-async-reduce-right/tree/deno" -click F href "https://github.com/stdlib-js/utils-async-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right -[production-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3f22669..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,224 +0,0 @@ - -{{alias}}( collection, initial, [options,] reducer, done ) - Applies a function against an accumulator and each element in a collection - and returns the accumulated result, iterating from right to left. - - When invoked, `reducer` is provided a maximum of five arguments: - - - `accumulator`: accumulated value - - `value`: collection value - - `index`: collection index - - `collection`: the input collection - - `next`: a callback to be invoked after processing a collection `value` - - The actual number of provided arguments depends on function length. If - `reducer` accepts three arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `next` - - If `reducer` accepts four arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `index` - - `next` - - For every other `reducer` signature, `reducer` is provided all five - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `accumulator`: accumulated value - - If a provided function calls the `next` callback with a truthy `error` - argument, the function suspends execution and immediately calls the `done` - callback for subsequent `error` handling. - - Execution is *not* guaranteed to be asynchronous. To guarantee asynchrony, - 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`). - - The function does not support dynamic collection resizing. - - If provided an empty collection, the function invokes the `done` callback - with the `initial` value as the second argument. - - The function does not skip `undefined` elements. - - When processing collection elements concurrently, *beware* of race - conditions when updating an accumulator. This is especially true when an - accumulator is a primitive (e.g., a number). In general, prefer object - accumulators. - - Parameters - ---------- - collection: Array|TypedArray|Object - Input collection over which to iterate. If provided an object, the - object must be array-like (excluding strings and functions). - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - reducer: Function - The function to invoke for each element in a collection. - - done: Function - A callback invoked either upon processing all collection elements or - upon encountering an error. - - Examples - -------- - // Basic usage: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, fcn, done ) - 3000 - 2500 - 1000 - 6500 - - // Limit number of concurrent invocations: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'limit': 2 }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 2500 - 3000 - 1000 - 6500 - - // Process concurrently: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'series': false }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 1000 - 2500 - 3000 - 6500 - - -{{alias}}.factory( [options,] fcn ) - Returns a function which applies a function against an accumulator and each - element in a collection and returns the accumulated result, iterating from - right to left. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - fcn: Function - The function to invoke for each element in a collection. - - Returns - ------- - out: Function - A function which invokes a function for each element in a collection. - - Examples - -------- - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > var opts = { 'series': false }; - > var f = {{alias}}.factory( opts, fcn ); - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > f( arr, acc, done ) - 1000 - 2500 - 3000 - 6500 - > acc = { 'sum': 0 }; - > arr = [ 1000, 1500, 2000 ]; - > f( arr, acc, done ) - 1000 - 1500 - 2000 - 4500 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 143a132..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,166 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unsafe-any */ - -import reduceRightAsync = require( './index' ); - -const reducer = ( acc: any, value: number, index: number, next: Function ) => { - acc.sum += value; - if ( index === void 0 ) { - throw new Error( '`index` is missing.' ); - } - next( null, acc ); -}; - -const done = ( error: Error | null, acc: any ) => { - if ( error ) { - throw error; - } - if ( acc === void 0 ) { - throw new Error( '`acc` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( 2, acc, reducer, done ); // $ExpectError - reduceRightAsync( false, acc, reducer, done ); // $ExpectError - reduceRightAsync( true, acc, reducer, done ); // $ExpectError - reduceRightAsync( {}, acc, reducer, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a predicate argument which is not a predicate function... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 2, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, false, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, true, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 'abc', done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, [], done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a done callback argument which is not a function having a supported signature... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 2 ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, false ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, true ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 'abc' ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, {} ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, [] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const acc = { 'sum': 0 }; - reduceRightAsync(); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, reducer, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - reduceRightAsync.factory( reducer ); // $ExpectType FactoryFunction - reduceRightAsync.factory( { 'series': true }, reducer ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - reduceRightAsync.factory( [], reducer ); // $ExpectError - reduceRightAsync.factory( 123, reducer ); // $ExpectError - reduceRightAsync.factory( 'abc', reducer ); // $ExpectError - reduceRightAsync.factory( false, reducer ); // $ExpectError - reduceRightAsync.factory( true, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not a predicate function... -{ - reduceRightAsync.factory( {} ); // $ExpectError - reduceRightAsync.factory( true ); // $ExpectError - reduceRightAsync.factory( false ); // $ExpectError - reduceRightAsync.factory( {}, 123 ); // $ExpectError - reduceRightAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1( 12, acc, done ); // $ExpectError - fcn1( true, acc, done ); // $ExpectError - fcn1( false, acc, done ); // $ExpectError - fcn1( {}, acc, done ); // $ExpectError - - fcn1( [ 3000, 2500, 1000 ], acc, 12 ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, true ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, false ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, '5' ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, {} ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, [] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1(); // $ExpectError - fcn1( [ 3000, 2500, 1000 ] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - reduceRightAsync.factory( { 'limit': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': true }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': false }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - reduceRightAsync.factory( { 'series': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': 12 }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - reduceRightAsync.factory(); // $ExpectError - reduceRightAsync.factory( {}, reducer, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index dd64345..0000000 --- a/examples/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var resolve = require( 'path' ).resolve; -var readFile = require( '@stdlib/fs-read-file' ); -var reduceRightAsync = require( './../lib' ); - -var files = [ - resolve( __dirname, '..', 'package.json' ), - resolve( __dirname, '..', 'README.md' ) -]; - -function done( error, acc ) { - if ( error ) { - throw error; - } - console.log( acc.count ); -} - -function read( acc, file, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( file, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( null, acc ); - } - acc.count += 1; - next( null, acc ); - } -} - -var acc = { - 'count': 0 -}; -reduceRightAsync( files, acc, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index b19e443..9dc0658 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { Collection } from '@stdlib/types/object'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..86b95e1 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import i from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";function d(i,t){return n(t)?(o(t,"thisArg")&&(i.thisArg=t.thisArg),o(t,"series")&&(i.series=t.series,!l(i.series))?new TypeError(s("0id30","series",i.series)):o(t,"limit")&&(i.limit=t.limit,!m(i.limit))?new TypeError(s("0id3b","limit",i.limit)):null):new TypeError(s("0id2h",t))}var f=()=>{};function h(i,t,e,s,r){var n,o,l,m,d,h;if(0===(m=i.length))return r(null,t);for(l=m0&&p();function p(){function r(i,e){if(!o){if(i)return o=!0,c(i);f("Accumulator: %s",JSON.stringify(e)),t=e,c()}}f("Collection element %d: %s.",d-=1,JSON.stringify(i[d])),3===s.length?s.call(e.thisArg,t,i[d],r):4===s.length?s.call(e.thisArg,t,i[d],d,r):s.call(e.thisArg,t,i[d],d,i,r)}function c(i){return i?(f("Encountered an error: %s",i.message),r(i)):(n+=1,d>0?p():n===m?r(null,t):void 0)}}function p(i,n){var o,l,m;if(o={},arguments.length>1){if(l=d(o,i))throw l;m=n}else m=i;if(!t(m))throw new TypeError(s("0id43",m));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=r),f;function f(i,r,n){if(!e(i))throw new TypeError(s("0idBO",i));if(!t(n))throw new TypeError(s("0id43",n));return h(i,r,o,m,(function(i,t){if(i)return n(i);n(null,t)}))}}function c(i,t,e,s,r){if(arguments.length<5)return p(e)(i,t,s);p(e,s)(i,t,r)}i(c,"factory",p);export{c as default,p as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..d8d8487 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/reduce_right.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean' ;\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\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( '0id2h', 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( '0id30', '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( '0id3b', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport logger from 'debug' ;\n\n\n// VARIABLES //\n\nvar debug = logger( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function' ;\nimport isCollection from '@stdlib/assert-is-collection' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport PINF from '@stdlib/constants-float64-pinf' ;\nimport validate from './validate.js' ;\nimport limit from './limit.js' ;\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0id43', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '0idBO', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0id43', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\n* @param {Collection} collection - input collection\n* @param {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file' ;\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right' ;\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport reduceRightAsync from './reduce_right.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( reduceRightAsync, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly"],"mappings":";;y1BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUR,EAAKK,SAGnDF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASR,EAAKS,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASP,QC7BrCU,SAkBJ,SAASF,EAAOG,EAAYC,EAAKb,EAAMc,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAAa,KAHbF,EAAMP,EAAWU,QAKhB,OAAOP,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMnB,EAAKS,MACTU,EAEAnB,EAAKS,MAGZE,EAAO,0BAA2BG,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdd,EAAO,kBAAmBiB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,KA3BDhB,EAAO,6BADPS,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM9B,EAAKI,QAASS,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM9B,EAAKI,QAASS,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM9B,EAAKI,QAASS,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,GAgCnE,SAASG,EAAMF,GACd,OAAKA,GACJd,EAAO,2BAA4Bc,EAAMM,SAClChB,EAAMU,KAEdT,GAAS,EAEJI,EAAM,EACHG,IAEHP,IAAUG,EAEPJ,EAAM,KAAMF,QAFpB,ICnCF,SAASmB,EAAS/B,EAASa,GAC1B,IAAId,EACAiC,EACAC,EAGJ,GADAlC,EAAO,GACFmC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMlC,EAAUC,EAAMC,GAErB,MAAMgC,EAEPC,EAAIpB,OAEJoB,EAAIjC,EAEL,IAAMmC,EAAYF,GACjB,MAAM,IAAI3B,UAAWC,EAAQ,QAAS0B,IAUvC,YARqB,IAAhBlC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ4B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIL,UAAWC,EAAQ,QAASI,IAEvC,IAAMwB,EAAYrB,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,OAAON,EAAOG,EAAY2B,EAASvC,EAAMkC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,OCvEf,SAASyB,EAAkB1B,EAAY2B,EAAStC,EAASa,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAS/B,EAAT+B,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAS/B,EAASa,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,GClB/C0B,EAAAH,EAAA,UAAAN"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 6d67be2..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var validate = require( './validate.js' ); -var limit = require( './limit.js' ); - - -// MAIN // - -/** -* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} last argument must be a function -* @returns {Function} function which invokes the provided function once for each element in a collection -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error, data ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var opts = { -* 'series': false -* }; -* -* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: -* var reduceRightAsync = factory( opts, read ); -* -* // Create a collection over which to iterate: -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* // Define a callback which handles errors: -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* // Run `read` for each element in `files`: -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, done ); -*/ -function factory( options, fcn ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = fcn; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '0id43', f ) ); - } - if ( opts.series === void 0 && opts.limit === void 0 ) { - opts.series = true; - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return reduceRightAsync; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * @private - * @param {Collection} collection - input collection - * @param {*} initial - initial value - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be a collection - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function reduceRightAsync( collection, initial, done ) { - if ( !isCollection( collection ) ) { - throw new TypeError( format( '0idBO', collection ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '0id43', done ) ); - } - return limit( collection, initial, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {*} [acc] - accumulated value - * @returns {void} - */ - function clbk( error, acc ) { - if ( error ) { - return done( error ); - } - done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 84aeb69..0000000 --- a/lib/index.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* @module @stdlib/utils-async-reduce-right -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' ); -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var reduceRightAsync = require( './reduce_right.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( reduceRightAsync, 'factory', factory ); - - -// EXPORTS // - -module.exports = reduceRightAsync; diff --git a/lib/limit.js b/lib/limit.js deleted file mode 100644 index cdb60af..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); - - -// VARIABLES // - -var debug = logger( 'reduce-right-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each element in a collection, limiting the number of concurrently pending functions and iterating from right to left. -* -* @private -* @param {Collection} collection - input collection -* @param {*} acc - initial value -* @param {Options} opts - function options -* @param {*} [opts.thisArg] - execution context -* @param {PositiveInteger} [opts.limit] - maximum number of pending function invocations -* @param {Function} fcn - function to invoke -* @param {Callback} done - function to invoke upon completion or upon encountering an error -* @returns {void} -*/ -function limit( collection, acc, opts, fcn, done ) { - var count; - var flg; - var lim; - var len; - var idx; - var i; - - len = collection.length; - debug( 'Collection length: %d', len ); - - if ( len === 0 ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - count = 0; - idx = len; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all collection elements... - if ( idx > 0 ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next element in a collection. - * - * @private - */ - function next() { - idx -= 1; - debug( 'Collection element %d: %s.', idx, JSON.stringify( collection[ idx ] ) ); - if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], cb ); - } else if ( fcn.length === 4 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, cb ); - } else { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len - } - /** - * Callback invoked once a provided function finishes processing a collection element. - * - * @private - * @param {*} [error] - error - * @param {*} [result] - accumulation result - * @returns {void} - */ - function cb( error, result ) { - if ( flg ) { - // Prevent further processing of collection elements: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Accumulator: %s', JSON.stringify( result ) ); - acc = result; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next collection element. - * - * @private - * @param {*} [error] - error - * @returns {void} - */ - function clbk( error ) { - if ( error ) { - debug( 'Encountered an error: %s', error.message ); - return done( error ); - } - count += 1; - debug( 'Processed %d of %d collection elements.', count, len ); - if ( idx > 0 ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/reduce_right.js b/lib/reduce_right.js deleted file mode 100644 index 9f016bf..0000000 --- a/lib/reduce_right.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param {Collection} collection - input collection -* @param {*} initial - initial value -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} second-to-last argument must be a function -* @throws {TypeError} last argument must be a function -* @returns {void} -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -function reduceRightAsync( collection, initial, options, fcn, done ) { - if ( arguments.length < 5 ) { - return factory( options )( collection, initial, fcn ); - } - factory( options, fcn )( collection, initial, done ); -} - - -// EXPORTS // - -module.exports = reduceRightAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 6292663..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @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 -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'thisArg': {}, -* 'series': false, -* 'limit': 10 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '0id2h', options ) ); - } - if ( hasOwnProp( options, 'thisArg' ) ) { - opts.thisArg = options.thisArg; - } - if ( hasOwnProp( options, 'series' ) ) { - opts.series = options.series; - if ( !isBoolean( opts.series ) ) { - return new TypeError( format( '0id30', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '0id3b', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 005e6d8..55f16d9 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.8", "description": "Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,43 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-boolean": "^0.0.x", - "@stdlib/assert-is-collection": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/assert-is-positive-integer": "^0.0.x", - "@stdlib/constants-float64-pinf": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/constants-float64-eps": "^0.0.x", - "@stdlib/fs-read-file": "^0.0.x", - "@stdlib/utils-noop": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..12d28c8 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 8244931..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1095 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( {}, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, next ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - factory( opts, next ); - }; - } -}); - -tape( 'the function returns a function (no options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided a collection (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a collection (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (1 argument)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (2 arguments)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with five arguments', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn() { - var value; - var next; - var acc; - var k; - - acc = arguments[ 0 ]; - value = arguments[ 1 ]; - k = arguments[ 2 ]; - next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( k, i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the returned function supports processing collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements concurrently', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 100, 250, 300 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements sequentially (limit = 1)', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of collection elements which are processed at any one time', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 250, 300, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 250, 100, 300 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var reduceRightAsync; - var arr; - - reduceRightAsync = factory( fcn ); - arr = []; - - reduceRightAsync( arr, 0, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var reduceRightAsync; - var obj; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = []; - obj = {}; - reduceRightAsync( arr, obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - i = 0; - - reduceRightAsync( arr, {}, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, acc ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the returned function does not skip empty elements', function test( t ) { - var reduceRightAsync; - var expected; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index f273a40..0000000 --- a/test/test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof reduceRightAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.reduce_right.js b/test/test.reduce_right.js deleted file mode 100644 index dc3e5d5..0000000 --- a/test/test.reduce_right.js +++ /dev/null @@ -1,1035 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var reduceRightAsync = require( './../lib/reduce_right.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a collection', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (no options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, next, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, 0 ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - reduceRightAsync( [ 1, 2, 3 ], 0, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (1 argument)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (2 arguments)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with five arguments', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn() { - var next; - var acc; - var v; - - next = arguments[ 4 ]; - acc = arguments[ 0 ]; - v = arguments[ 1 ]; - - i -= 1; - j += 1; - - t.strictEqual( v, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, v ); - - function onTimeout() { - acc.sum += v; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'by default, the function processes collection elements sequentially', function test( t ) { - var values; - var count; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements concurrently', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 100, 250, 300 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': true - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially (limit = 1)', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var arr; - var ctx; - - arr = [ 3, 2, 1 ]; - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 3, 2, 1 ]; - opts = { - 'series': true - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 250, 100, 300 ]; - opts = { - 'limit': 2 - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var arr = []; - reduceRightAsync( arr, 0, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var arr = []; - var obj = {}; - - reduceRightAsync( arr, obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - arr = [ 3, 2, 1 ]; - i = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, value ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the function does not skip empty elements', function test( t ) { - var expected; - var arr; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, fcn, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 7660838..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,181 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `limit` option which is not a positive integer', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - -5, - 0, - 3.14, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'limit': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `series` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'series': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function accepts any value for the `thisArg` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'thisArg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err, null, 'returns null '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'thisArg': {}, - 'series': false, - 'limit': 10 - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From ea438e5d56e9492d63fd936c39a5305baea646d7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 19:57:43 +0000 Subject: [PATCH 005/147] Transform error messages --- lib/factory.js | 8 ++++---- lib/validate.js | 8 ++++---- package.json | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index a627d69..6d67be2 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -22,7 +22,7 @@ var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var PINF = require( '@stdlib/constants-float64-pinf' ); var validate = require( './validate.js' ); var limit = require( './limit.js' ); @@ -110,7 +110,7 @@ function factory( options, fcn ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '0id43', f ) ); } if ( opts.series === void 0 && opts.limit === void 0 ) { opts.series = true; @@ -135,10 +135,10 @@ function factory( options, fcn ) { */ function reduceRightAsync( collection, initial, done ) { if ( !isCollection( collection ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a collection. Value: `%s`.', collection ) ); + throw new TypeError( format( '0idBO', collection ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '0id43', done ) ); } return limit( collection, initial, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index 9ba927e..6292663 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,7 +54,7 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0id2h', options ) ); } if ( hasOwnProp( options, 'thisArg' ) ) { opts.thisArg = options.thisArg; @@ -62,13 +62,13 @@ function validate( opts, options ) { if ( hasOwnProp( options, 'series' ) ) { opts.series = options.series; if ( !isBoolean( opts.series ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'series', opts.series ) ); + return new TypeError( format( '0id30', 'series', opts.series ) ); } } if ( hasOwnProp( options, 'limit' ) ) { opts.limit = options.limit; if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'limit', opts.limit ) ); + return new TypeError( format( '0id3b', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index fb48f96..005e6d8 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-plain-object": "^0.0.x", "@stdlib/assert-is-positive-integer": "^0.0.x", "@stdlib/constants-float64-pinf": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x", "debug": "^2.6.9" From 195de9f640a007290c0807e574f438fe64a5f238 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Jul 2022 10:33:31 +0000 Subject: [PATCH 006/147] Remove files --- index.d.ts | 415 -------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 3109 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 9dc0658..0000000 --- a/index.d.ts +++ /dev/null @@ -1,415 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Collection } from '@stdlib/types/object'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * The maximum number of pending invocations at any one time. - */ - limit?: number; - - /** - * Boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection (default: true). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback function. -*/ -type Nullary = () => void; - -/** -* Callback function. -* -* @param error - encountered error or null -*/ -type Unary = ( error: Error | null ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Binary = ( error: Error | null, accumulator: any ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param next - a callback to be invoked after processing a collection `value` -*/ -type TernaryReducer = ( accumulator: any, value: any, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuaternaryReducer = ( accumulator: any, value: any, index: number, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuinaryReducer = ( accumulator: any, value: any, index: number, collection: Collection, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type Reducer = TernaryReducer | QuaternaryReducer | QuinaryReducer; - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result. -* -* @param collection - input collection -* @param initial - initial value -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( collection: Collection, initial: any, done: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Interface for `reduceRightAsync`. -*/ -interface ReduceRightAsync { - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, {}, read, done ); - */ - ( collection: Collection, initial: any, options: Options, reducer: Reducer, done: Callback ): void; // tslint-disable-line max-line-length - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, read, done ); - */ - ( collection: Collection, initial: any, reducer: Reducer, done: Callback ): void; // tslint-disable-line max-line-length - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @throws must provide valid options - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var opts = { - * 'series': false - * }; - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( opts, read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( options: Options, reducer: Reducer ): FactoryFunction; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param reducer - function to invoke for each element in a collection - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( reducer: Reducer ): FactoryFunction; -} - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param collection - input collection -* @param initial - initial value -* @param options - function options -* @param options.thisArg - execution context -* @param options.limit - maximum number of pending invocations at any one time -* @param 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 (default: true) -* @param reducer - function to invoke for each element in a collection -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( `@stdlib/fs/read-file` ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -declare var reduceRightAsync: ReduceRightAsync; - - -// EXPORTS // - -export = reduceRightAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 86b95e1..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import i from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";function d(i,t){return n(t)?(o(t,"thisArg")&&(i.thisArg=t.thisArg),o(t,"series")&&(i.series=t.series,!l(i.series))?new TypeError(s("0id30","series",i.series)):o(t,"limit")&&(i.limit=t.limit,!m(i.limit))?new TypeError(s("0id3b","limit",i.limit)):null):new TypeError(s("0id2h",t))}var f=()=>{};function h(i,t,e,s,r){var n,o,l,m,d,h;if(0===(m=i.length))return r(null,t);for(l=m0&&p();function p(){function r(i,e){if(!o){if(i)return o=!0,c(i);f("Accumulator: %s",JSON.stringify(e)),t=e,c()}}f("Collection element %d: %s.",d-=1,JSON.stringify(i[d])),3===s.length?s.call(e.thisArg,t,i[d],r):4===s.length?s.call(e.thisArg,t,i[d],d,r):s.call(e.thisArg,t,i[d],d,i,r)}function c(i){return i?(f("Encountered an error: %s",i.message),r(i)):(n+=1,d>0?p():n===m?r(null,t):void 0)}}function p(i,n){var o,l,m;if(o={},arguments.length>1){if(l=d(o,i))throw l;m=n}else m=i;if(!t(m))throw new TypeError(s("0id43",m));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=r),f;function f(i,r,n){if(!e(i))throw new TypeError(s("0idBO",i));if(!t(n))throw new TypeError(s("0id43",n));return h(i,r,o,m,(function(i,t){if(i)return n(i);n(null,t)}))}}function c(i,t,e,s,r){if(arguments.length<5)return p(e)(i,t,s);p(e,s)(i,t,r)}i(c,"factory",p);export{c as default,p as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index d8d8487..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/reduce_right.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean' ;\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\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( '0id2h', 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( '0id30', '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( '0id3b', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport logger from 'debug' ;\n\n\n// VARIABLES //\n\nvar debug = logger( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function' ;\nimport isCollection from '@stdlib/assert-is-collection' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport PINF from '@stdlib/constants-float64-pinf' ;\nimport validate from './validate.js' ;\nimport limit from './limit.js' ;\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0id43', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '0idBO', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0id43', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\n* @param {Collection} collection - input collection\n* @param {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file' ;\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right' ;\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport reduceRightAsync from './reduce_right.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( reduceRightAsync, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly"],"mappings":";;y1BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUR,EAAKK,SAGnDF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASR,EAAKS,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASP,QC7BrCU,SAkBJ,SAASF,EAAOG,EAAYC,EAAKb,EAAMc,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAAa,KAHbF,EAAMP,EAAWU,QAKhB,OAAOP,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMnB,EAAKS,MACTU,EAEAnB,EAAKS,MAGZE,EAAO,0BAA2BG,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdd,EAAO,kBAAmBiB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,KA3BDhB,EAAO,6BADPS,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM9B,EAAKI,QAASS,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM9B,EAAKI,QAASS,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM9B,EAAKI,QAASS,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,GAgCnE,SAASG,EAAMF,GACd,OAAKA,GACJd,EAAO,2BAA4Bc,EAAMM,SAClChB,EAAMU,KAEdT,GAAS,EAEJI,EAAM,EACHG,IAEHP,IAAUG,EAEPJ,EAAM,KAAMF,QAFpB,ICnCF,SAASmB,EAAS/B,EAASa,GAC1B,IAAId,EACAiC,EACAC,EAGJ,GADAlC,EAAO,GACFmC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMlC,EAAUC,EAAMC,GAErB,MAAMgC,EAEPC,EAAIpB,OAEJoB,EAAIjC,EAEL,IAAMmC,EAAYF,GACjB,MAAM,IAAI3B,UAAWC,EAAQ,QAAS0B,IAUvC,YARqB,IAAhBlC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ4B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIL,UAAWC,EAAQ,QAASI,IAEvC,IAAMwB,EAAYrB,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,OAAON,EAAOG,EAAY2B,EAASvC,EAAMkC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,OCvEf,SAASyB,EAAkB1B,EAAY2B,EAAStC,EAASa,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAS/B,EAAT+B,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAS/B,EAASa,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,GClB/C0B,EAAAH,EAAA,UAAAN"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 12d28c8..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From f1ffb4d219d4bd15476c1408bc74b8d87ce542a4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Jul 2022 10:34:05 +0000 Subject: [PATCH 007/147] Auto-generated commit --- .editorconfig | 181 -- .eslintrc.js | 1 - .gitattributes | 33 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 681 ------ .github/workflows/publish.yml | 157 -- .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 -- .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 -- .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 ---- README.md | 47 +- benchmark/benchmark.factory.js | 73 - benchmark/benchmark.js | 160 -- branches.md | 53 - docs/repl.txt | 224 -- docs/types/test.ts | 166 -- examples/index.js | 55 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 165 -- lib/index.js | 77 - lib/limit.js | 142 -- lib/reduce_right.js | 96 - lib/validate.js | 80 - package.json | 64 +- stats.html | 2689 +++++++++++++++++++++ test/test.factory.js | 1095 --------- test/test.js | 38 - test/test.reduce_right.js | 1035 -------- test/test.validate.js | 181 -- 44 files changed, 2720 insertions(+), 6576 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/limit.js delete mode 100644 lib/reduce_right.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.reduce_right.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 7212d81..0000000 --- a/.gitattributes +++ /dev/null @@ -1,33 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 43067d5..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-07-01T01:08:36.717Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1e08946..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 29bf533..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a7a7f51..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.9.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 663f5df..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 39b1613..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 7ca169c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 8 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "::set-output name=package_name::$name" - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "::set-output name=data::$data" - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v2 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v2 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 128c22e..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,681 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the repository: - push: - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs rm -rf - - git add -A - git commit -m "Remove files" - - git merge -s recursive -X theirs origin/production --allow-unrelated-histories - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch or create new branch tag: - - name: 'Push changes to `deno` branch or create new branch tag' - run: | - SLUG=${{ github.repository }} - VERSION=$(echo ${{ github.ref }} | sed -E -n 's/refs\/tags\/?(v[0-9]+.[0-9]+.[0-9]+).*/\1/p') - if [ -z "$VERSION" ]; then - echo "Workflow job was not triggered by a new tag...." - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - else - echo "Workflow job was triggered by a new tag: $VERSION" - echo "Creating new bundle branch tag of the form $VERSION-deno" - git tag -a $VERSION-deno -m "$VERSION-deno" - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" $VERSION-deno - fi - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs rm -rf - - git add -A - git commit -m "Remove files" - - git merge -s recursive -X theirs origin/production --allow-unrelated-histories - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "::set-output name=alias::${alias}" - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -447,7 +446,7 @@ reduceRightAsync( files, acc, read, done ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -515,11 +514,11 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right +[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right/tree/esm -[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce +[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/tree/esm diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 46d8b83..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var reduceRightAsync; - var arr; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - reduceRightAsync = factory( onItem ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - var acc; - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 6ad0714..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var reduceRightAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=false', function benchmark( b ) { - var opts; - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'series': false - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var arr; - var len; - var acc; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'limit': 3 - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 2aded98..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right" -click B href "https://github.com/stdlib-js/utils-async-reduce-right/tree/main" -click C href "https://github.com/stdlib-js/utils-async-reduce-right/tree/production" -click D href "https://github.com/stdlib-js/utils-async-reduce-right/tree/esm" -click E href "https://github.com/stdlib-js/utils-async-reduce-right/tree/deno" -click F href "https://github.com/stdlib-js/utils-async-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right -[production-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3f22669..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,224 +0,0 @@ - -{{alias}}( collection, initial, [options,] reducer, done ) - Applies a function against an accumulator and each element in a collection - and returns the accumulated result, iterating from right to left. - - When invoked, `reducer` is provided a maximum of five arguments: - - - `accumulator`: accumulated value - - `value`: collection value - - `index`: collection index - - `collection`: the input collection - - `next`: a callback to be invoked after processing a collection `value` - - The actual number of provided arguments depends on function length. If - `reducer` accepts three arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `next` - - If `reducer` accepts four arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `index` - - `next` - - For every other `reducer` signature, `reducer` is provided all five - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `accumulator`: accumulated value - - If a provided function calls the `next` callback with a truthy `error` - argument, the function suspends execution and immediately calls the `done` - callback for subsequent `error` handling. - - Execution is *not* guaranteed to be asynchronous. To guarantee asynchrony, - 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`). - - The function does not support dynamic collection resizing. - - If provided an empty collection, the function invokes the `done` callback - with the `initial` value as the second argument. - - The function does not skip `undefined` elements. - - When processing collection elements concurrently, *beware* of race - conditions when updating an accumulator. This is especially true when an - accumulator is a primitive (e.g., a number). In general, prefer object - accumulators. - - Parameters - ---------- - collection: Array|TypedArray|Object - Input collection over which to iterate. If provided an object, the - object must be array-like (excluding strings and functions). - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - reducer: Function - The function to invoke for each element in a collection. - - done: Function - A callback invoked either upon processing all collection elements or - upon encountering an error. - - Examples - -------- - // Basic usage: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, fcn, done ) - 3000 - 2500 - 1000 - 6500 - - // Limit number of concurrent invocations: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'limit': 2 }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 2500 - 3000 - 1000 - 6500 - - // Process concurrently: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'series': false }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 1000 - 2500 - 3000 - 6500 - - -{{alias}}.factory( [options,] fcn ) - Returns a function which applies a function against an accumulator and each - element in a collection and returns the accumulated result, iterating from - right to left. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - fcn: Function - The function to invoke for each element in a collection. - - Returns - ------- - out: Function - A function which invokes a function for each element in a collection. - - Examples - -------- - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > var opts = { 'series': false }; - > var f = {{alias}}.factory( opts, fcn ); - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > f( arr, acc, done ) - 1000 - 2500 - 3000 - 6500 - > acc = { 'sum': 0 }; - > arr = [ 1000, 1500, 2000 ]; - > f( arr, acc, done ) - 1000 - 1500 - 2000 - 4500 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 143a132..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,166 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unsafe-any */ - -import reduceRightAsync = require( './index' ); - -const reducer = ( acc: any, value: number, index: number, next: Function ) => { - acc.sum += value; - if ( index === void 0 ) { - throw new Error( '`index` is missing.' ); - } - next( null, acc ); -}; - -const done = ( error: Error | null, acc: any ) => { - if ( error ) { - throw error; - } - if ( acc === void 0 ) { - throw new Error( '`acc` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( 2, acc, reducer, done ); // $ExpectError - reduceRightAsync( false, acc, reducer, done ); // $ExpectError - reduceRightAsync( true, acc, reducer, done ); // $ExpectError - reduceRightAsync( {}, acc, reducer, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a predicate argument which is not a predicate function... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 2, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, false, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, true, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 'abc', done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, [], done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a done callback argument which is not a function having a supported signature... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 2 ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, false ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, true ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 'abc' ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, {} ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, [] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const acc = { 'sum': 0 }; - reduceRightAsync(); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, reducer, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - reduceRightAsync.factory( reducer ); // $ExpectType FactoryFunction - reduceRightAsync.factory( { 'series': true }, reducer ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - reduceRightAsync.factory( [], reducer ); // $ExpectError - reduceRightAsync.factory( 123, reducer ); // $ExpectError - reduceRightAsync.factory( 'abc', reducer ); // $ExpectError - reduceRightAsync.factory( false, reducer ); // $ExpectError - reduceRightAsync.factory( true, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not a predicate function... -{ - reduceRightAsync.factory( {} ); // $ExpectError - reduceRightAsync.factory( true ); // $ExpectError - reduceRightAsync.factory( false ); // $ExpectError - reduceRightAsync.factory( {}, 123 ); // $ExpectError - reduceRightAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1( 12, acc, done ); // $ExpectError - fcn1( true, acc, done ); // $ExpectError - fcn1( false, acc, done ); // $ExpectError - fcn1( {}, acc, done ); // $ExpectError - - fcn1( [ 3000, 2500, 1000 ], acc, 12 ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, true ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, false ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, '5' ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, {} ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, [] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1(); // $ExpectError - fcn1( [ 3000, 2500, 1000 ] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - reduceRightAsync.factory( { 'limit': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': true }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': false }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - reduceRightAsync.factory( { 'series': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': 12 }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - reduceRightAsync.factory(); // $ExpectError - reduceRightAsync.factory( {}, reducer, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index dd64345..0000000 --- a/examples/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var resolve = require( 'path' ).resolve; -var readFile = require( '@stdlib/fs-read-file' ); -var reduceRightAsync = require( './../lib' ); - -var files = [ - resolve( __dirname, '..', 'package.json' ), - resolve( __dirname, '..', 'README.md' ) -]; - -function done( error, acc ) { - if ( error ) { - throw error; - } - console.log( acc.count ); -} - -function read( acc, file, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( file, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( null, acc ); - } - acc.count += 1; - next( null, acc ); - } -} - -var acc = { - 'count': 0 -}; -reduceRightAsync( files, acc, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index b19e443..9dc0658 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { Collection } from '@stdlib/types/object'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..86b95e1 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import i from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";function d(i,t){return n(t)?(o(t,"thisArg")&&(i.thisArg=t.thisArg),o(t,"series")&&(i.series=t.series,!l(i.series))?new TypeError(s("0id30","series",i.series)):o(t,"limit")&&(i.limit=t.limit,!m(i.limit))?new TypeError(s("0id3b","limit",i.limit)):null):new TypeError(s("0id2h",t))}var f=()=>{};function h(i,t,e,s,r){var n,o,l,m,d,h;if(0===(m=i.length))return r(null,t);for(l=m0&&p();function p(){function r(i,e){if(!o){if(i)return o=!0,c(i);f("Accumulator: %s",JSON.stringify(e)),t=e,c()}}f("Collection element %d: %s.",d-=1,JSON.stringify(i[d])),3===s.length?s.call(e.thisArg,t,i[d],r):4===s.length?s.call(e.thisArg,t,i[d],d,r):s.call(e.thisArg,t,i[d],d,i,r)}function c(i){return i?(f("Encountered an error: %s",i.message),r(i)):(n+=1,d>0?p():n===m?r(null,t):void 0)}}function p(i,n){var o,l,m;if(o={},arguments.length>1){if(l=d(o,i))throw l;m=n}else m=i;if(!t(m))throw new TypeError(s("0id43",m));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=r),f;function f(i,r,n){if(!e(i))throw new TypeError(s("0idBO",i));if(!t(n))throw new TypeError(s("0id43",n));return h(i,r,o,m,(function(i,t){if(i)return n(i);n(null,t)}))}}function c(i,t,e,s,r){if(arguments.length<5)return p(e)(i,t,s);p(e,s)(i,t,r)}i(c,"factory",p);export{c as default,p as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..d8d8487 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/reduce_right.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean' ;\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\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( '0id2h', 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( '0id30', '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( '0id3b', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport logger from 'debug' ;\n\n\n// VARIABLES //\n\nvar debug = logger( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function' ;\nimport isCollection from '@stdlib/assert-is-collection' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport PINF from '@stdlib/constants-float64-pinf' ;\nimport validate from './validate.js' ;\nimport limit from './limit.js' ;\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0id43', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '0idBO', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0id43', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\n* @param {Collection} collection - input collection\n* @param {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file' ;\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right' ;\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport reduceRightAsync from './reduce_right.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( reduceRightAsync, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly"],"mappings":";;y1BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUR,EAAKK,SAGnDF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASR,EAAKS,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASP,QC7BrCU,SAkBJ,SAASF,EAAOG,EAAYC,EAAKb,EAAMc,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAAa,KAHbF,EAAMP,EAAWU,QAKhB,OAAOP,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMnB,EAAKS,MACTU,EAEAnB,EAAKS,MAGZE,EAAO,0BAA2BG,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdd,EAAO,kBAAmBiB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,KA3BDhB,EAAO,6BADPS,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM9B,EAAKI,QAASS,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM9B,EAAKI,QAASS,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM9B,EAAKI,QAASS,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,GAgCnE,SAASG,EAAMF,GACd,OAAKA,GACJd,EAAO,2BAA4Bc,EAAMM,SAClChB,EAAMU,KAEdT,GAAS,EAEJI,EAAM,EACHG,IAEHP,IAAUG,EAEPJ,EAAM,KAAMF,QAFpB,ICnCF,SAASmB,EAAS/B,EAASa,GAC1B,IAAId,EACAiC,EACAC,EAGJ,GADAlC,EAAO,GACFmC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMlC,EAAUC,EAAMC,GAErB,MAAMgC,EAEPC,EAAIpB,OAEJoB,EAAIjC,EAEL,IAAMmC,EAAYF,GACjB,MAAM,IAAI3B,UAAWC,EAAQ,QAAS0B,IAUvC,YARqB,IAAhBlC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ4B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIL,UAAWC,EAAQ,QAASI,IAEvC,IAAMwB,EAAYrB,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,OAAON,EAAOG,EAAY2B,EAASvC,EAAMkC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,OCvEf,SAASyB,EAAkB1B,EAAY2B,EAAStC,EAASa,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAS/B,EAAT+B,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAS/B,EAASa,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,GClB/C0B,EAAAH,EAAA,UAAAN"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 6d67be2..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var validate = require( './validate.js' ); -var limit = require( './limit.js' ); - - -// MAIN // - -/** -* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} last argument must be a function -* @returns {Function} function which invokes the provided function once for each element in a collection -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error, data ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var opts = { -* 'series': false -* }; -* -* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: -* var reduceRightAsync = factory( opts, read ); -* -* // Create a collection over which to iterate: -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* // Define a callback which handles errors: -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* // Run `read` for each element in `files`: -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, done ); -*/ -function factory( options, fcn ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = fcn; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '0id43', f ) ); - } - if ( opts.series === void 0 && opts.limit === void 0 ) { - opts.series = true; - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return reduceRightAsync; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * @private - * @param {Collection} collection - input collection - * @param {*} initial - initial value - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be a collection - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function reduceRightAsync( collection, initial, done ) { - if ( !isCollection( collection ) ) { - throw new TypeError( format( '0idBO', collection ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '0id43', done ) ); - } - return limit( collection, initial, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {*} [acc] - accumulated value - * @returns {void} - */ - function clbk( error, acc ) { - if ( error ) { - return done( error ); - } - done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 84aeb69..0000000 --- a/lib/index.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* @module @stdlib/utils-async-reduce-right -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' ); -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var reduceRightAsync = require( './reduce_right.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( reduceRightAsync, 'factory', factory ); - - -// EXPORTS // - -module.exports = reduceRightAsync; diff --git a/lib/limit.js b/lib/limit.js deleted file mode 100644 index cdb60af..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); - - -// VARIABLES // - -var debug = logger( 'reduce-right-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each element in a collection, limiting the number of concurrently pending functions and iterating from right to left. -* -* @private -* @param {Collection} collection - input collection -* @param {*} acc - initial value -* @param {Options} opts - function options -* @param {*} [opts.thisArg] - execution context -* @param {PositiveInteger} [opts.limit] - maximum number of pending function invocations -* @param {Function} fcn - function to invoke -* @param {Callback} done - function to invoke upon completion or upon encountering an error -* @returns {void} -*/ -function limit( collection, acc, opts, fcn, done ) { - var count; - var flg; - var lim; - var len; - var idx; - var i; - - len = collection.length; - debug( 'Collection length: %d', len ); - - if ( len === 0 ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - count = 0; - idx = len; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all collection elements... - if ( idx > 0 ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next element in a collection. - * - * @private - */ - function next() { - idx -= 1; - debug( 'Collection element %d: %s.', idx, JSON.stringify( collection[ idx ] ) ); - if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], cb ); - } else if ( fcn.length === 4 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, cb ); - } else { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len - } - /** - * Callback invoked once a provided function finishes processing a collection element. - * - * @private - * @param {*} [error] - error - * @param {*} [result] - accumulation result - * @returns {void} - */ - function cb( error, result ) { - if ( flg ) { - // Prevent further processing of collection elements: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Accumulator: %s', JSON.stringify( result ) ); - acc = result; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next collection element. - * - * @private - * @param {*} [error] - error - * @returns {void} - */ - function clbk( error ) { - if ( error ) { - debug( 'Encountered an error: %s', error.message ); - return done( error ); - } - count += 1; - debug( 'Processed %d of %d collection elements.', count, len ); - if ( idx > 0 ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/reduce_right.js b/lib/reduce_right.js deleted file mode 100644 index 9f016bf..0000000 --- a/lib/reduce_right.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param {Collection} collection - input collection -* @param {*} initial - initial value -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} second-to-last argument must be a function -* @throws {TypeError} last argument must be a function -* @returns {void} -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -function reduceRightAsync( collection, initial, options, fcn, done ) { - if ( arguments.length < 5 ) { - return factory( options )( collection, initial, fcn ); - } - factory( options, fcn )( collection, initial, done ); -} - - -// EXPORTS // - -module.exports = reduceRightAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 6292663..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @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 -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'thisArg': {}, -* 'series': false, -* 'limit': 10 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '0id2h', options ) ); - } - if ( hasOwnProp( options, 'thisArg' ) ) { - opts.thisArg = options.thisArg; - } - if ( hasOwnProp( options, 'series' ) ) { - opts.series = options.series; - if ( !isBoolean( opts.series ) ) { - return new TypeError( format( '0id30', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '0id3b', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 005e6d8..55f16d9 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.8", "description": "Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,43 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-boolean": "^0.0.x", - "@stdlib/assert-is-collection": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/assert-is-positive-integer": "^0.0.x", - "@stdlib/constants-float64-pinf": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/constants-float64-eps": "^0.0.x", - "@stdlib/fs-read-file": "^0.0.x", - "@stdlib/utils-noop": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..dd6f7c9 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 8244931..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1095 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( {}, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, next ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - factory( opts, next ); - }; - } -}); - -tape( 'the function returns a function (no options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided a collection (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a collection (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (1 argument)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (2 arguments)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with five arguments', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn() { - var value; - var next; - var acc; - var k; - - acc = arguments[ 0 ]; - value = arguments[ 1 ]; - k = arguments[ 2 ]; - next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( k, i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the returned function supports processing collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements concurrently', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 100, 250, 300 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements sequentially (limit = 1)', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of collection elements which are processed at any one time', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 250, 300, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 250, 100, 300 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var reduceRightAsync; - var arr; - - reduceRightAsync = factory( fcn ); - arr = []; - - reduceRightAsync( arr, 0, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var reduceRightAsync; - var obj; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = []; - obj = {}; - reduceRightAsync( arr, obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - i = 0; - - reduceRightAsync( arr, {}, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, acc ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the returned function does not skip empty elements', function test( t ) { - var reduceRightAsync; - var expected; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index f273a40..0000000 --- a/test/test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof reduceRightAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.reduce_right.js b/test/test.reduce_right.js deleted file mode 100644 index dc3e5d5..0000000 --- a/test/test.reduce_right.js +++ /dev/null @@ -1,1035 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var reduceRightAsync = require( './../lib/reduce_right.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a collection', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (no options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, next, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, 0 ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - reduceRightAsync( [ 1, 2, 3 ], 0, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (1 argument)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (2 arguments)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with five arguments', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn() { - var next; - var acc; - var v; - - next = arguments[ 4 ]; - acc = arguments[ 0 ]; - v = arguments[ 1 ]; - - i -= 1; - j += 1; - - t.strictEqual( v, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, v ); - - function onTimeout() { - acc.sum += v; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'by default, the function processes collection elements sequentially', function test( t ) { - var values; - var count; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements concurrently', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 100, 250, 300 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': true - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially (limit = 1)', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var arr; - var ctx; - - arr = [ 3, 2, 1 ]; - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 3, 2, 1 ]; - opts = { - 'series': true - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 250, 100, 300 ]; - opts = { - 'limit': 2 - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var arr = []; - reduceRightAsync( arr, 0, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var arr = []; - var obj = {}; - - reduceRightAsync( arr, obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - arr = [ 3, 2, 1 ]; - i = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, value ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the function does not skip empty elements', function test( t ) { - var expected; - var arr; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, fcn, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 7660838..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,181 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `limit` option which is not a positive integer', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - -5, - 0, - 3.14, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'limit': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `series` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'series': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function accepts any value for the `thisArg` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'thisArg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err, null, 'returns null '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'thisArg': {}, - 'series': false, - 'limit': 10 - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From f37e047d621de03b8c64d6e55a9c2e42d3288834 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 5 Jul 2022 12:53:48 +0000 Subject: [PATCH 008/147] Transform error messages --- lib/factory.js | 8 ++++---- lib/validate.js | 8 ++++---- package.json | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index a627d69..6d67be2 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -22,7 +22,7 @@ var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var PINF = require( '@stdlib/constants-float64-pinf' ); var validate = require( './validate.js' ); var limit = require( './limit.js' ); @@ -110,7 +110,7 @@ function factory( options, fcn ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '0id43', f ) ); } if ( opts.series === void 0 && opts.limit === void 0 ) { opts.series = true; @@ -135,10 +135,10 @@ function factory( options, fcn ) { */ function reduceRightAsync( collection, initial, done ) { if ( !isCollection( collection ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a collection. Value: `%s`.', collection ) ); + throw new TypeError( format( '0idBO', collection ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '0id43', done ) ); } return limit( collection, initial, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index 9ba927e..6292663 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,7 +54,7 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0id2h', options ) ); } if ( hasOwnProp( options, 'thisArg' ) ) { opts.thisArg = options.thisArg; @@ -62,13 +62,13 @@ function validate( opts, options ) { if ( hasOwnProp( options, 'series' ) ) { opts.series = options.series; if ( !isBoolean( opts.series ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'series', opts.series ) ); + return new TypeError( format( '0id30', 'series', opts.series ) ); } } if ( hasOwnProp( options, 'limit' ) ) { opts.limit = options.limit; if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'limit', opts.limit ) ); + return new TypeError( format( '0id3b', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index fb48f96..005e6d8 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-plain-object": "^0.0.x", "@stdlib/assert-is-positive-integer": "^0.0.x", "@stdlib/constants-float64-pinf": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x", "debug": "^2.6.9" From 3676405c681ac84cc6d6fd4a17c3902db4baa4e9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 5 Jul 2022 14:03:46 +0000 Subject: [PATCH 009/147] Remove files --- index.d.ts | 415 -------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 3109 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 9dc0658..0000000 --- a/index.d.ts +++ /dev/null @@ -1,415 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Collection } from '@stdlib/types/object'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * The maximum number of pending invocations at any one time. - */ - limit?: number; - - /** - * Boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection (default: true). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback function. -*/ -type Nullary = () => void; - -/** -* Callback function. -* -* @param error - encountered error or null -*/ -type Unary = ( error: Error | null ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Binary = ( error: Error | null, accumulator: any ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param next - a callback to be invoked after processing a collection `value` -*/ -type TernaryReducer = ( accumulator: any, value: any, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuaternaryReducer = ( accumulator: any, value: any, index: number, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuinaryReducer = ( accumulator: any, value: any, index: number, collection: Collection, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type Reducer = TernaryReducer | QuaternaryReducer | QuinaryReducer; - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result. -* -* @param collection - input collection -* @param initial - initial value -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( collection: Collection, initial: any, done: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Interface for `reduceRightAsync`. -*/ -interface ReduceRightAsync { - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, {}, read, done ); - */ - ( collection: Collection, initial: any, options: Options, reducer: Reducer, done: Callback ): void; // tslint-disable-line max-line-length - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, read, done ); - */ - ( collection: Collection, initial: any, reducer: Reducer, done: Callback ): void; // tslint-disable-line max-line-length - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @throws must provide valid options - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var opts = { - * 'series': false - * }; - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( opts, read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( options: Options, reducer: Reducer ): FactoryFunction; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param reducer - function to invoke for each element in a collection - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( reducer: Reducer ): FactoryFunction; -} - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param collection - input collection -* @param initial - initial value -* @param options - function options -* @param options.thisArg - execution context -* @param options.limit - maximum number of pending invocations at any one time -* @param 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 (default: true) -* @param reducer - function to invoke for each element in a collection -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( `@stdlib/fs/read-file` ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -declare var reduceRightAsync: ReduceRightAsync; - - -// EXPORTS // - -export = reduceRightAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 86b95e1..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import i from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";function d(i,t){return n(t)?(o(t,"thisArg")&&(i.thisArg=t.thisArg),o(t,"series")&&(i.series=t.series,!l(i.series))?new TypeError(s("0id30","series",i.series)):o(t,"limit")&&(i.limit=t.limit,!m(i.limit))?new TypeError(s("0id3b","limit",i.limit)):null):new TypeError(s("0id2h",t))}var f=()=>{};function h(i,t,e,s,r){var n,o,l,m,d,h;if(0===(m=i.length))return r(null,t);for(l=m0&&p();function p(){function r(i,e){if(!o){if(i)return o=!0,c(i);f("Accumulator: %s",JSON.stringify(e)),t=e,c()}}f("Collection element %d: %s.",d-=1,JSON.stringify(i[d])),3===s.length?s.call(e.thisArg,t,i[d],r):4===s.length?s.call(e.thisArg,t,i[d],d,r):s.call(e.thisArg,t,i[d],d,i,r)}function c(i){return i?(f("Encountered an error: %s",i.message),r(i)):(n+=1,d>0?p():n===m?r(null,t):void 0)}}function p(i,n){var o,l,m;if(o={},arguments.length>1){if(l=d(o,i))throw l;m=n}else m=i;if(!t(m))throw new TypeError(s("0id43",m));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=r),f;function f(i,r,n){if(!e(i))throw new TypeError(s("0idBO",i));if(!t(n))throw new TypeError(s("0id43",n));return h(i,r,o,m,(function(i,t){if(i)return n(i);n(null,t)}))}}function c(i,t,e,s,r){if(arguments.length<5)return p(e)(i,t,s);p(e,s)(i,t,r)}i(c,"factory",p);export{c as default,p as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index d8d8487..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/reduce_right.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean' ;\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\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( '0id2h', 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( '0id30', '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( '0id3b', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport logger from 'debug' ;\n\n\n// VARIABLES //\n\nvar debug = logger( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function' ;\nimport isCollection from '@stdlib/assert-is-collection' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport PINF from '@stdlib/constants-float64-pinf' ;\nimport validate from './validate.js' ;\nimport limit from './limit.js' ;\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0id43', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '0idBO', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0id43', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\n* @param {Collection} collection - input collection\n* @param {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file' ;\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right' ;\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport reduceRightAsync from './reduce_right.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( reduceRightAsync, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly"],"mappings":";;y1BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUR,EAAKK,SAGnDF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASR,EAAKS,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASP,QC7BrCU,SAkBJ,SAASF,EAAOG,EAAYC,EAAKb,EAAMc,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAAa,KAHbF,EAAMP,EAAWU,QAKhB,OAAOP,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMnB,EAAKS,MACTU,EAEAnB,EAAKS,MAGZE,EAAO,0BAA2BG,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdd,EAAO,kBAAmBiB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,KA3BDhB,EAAO,6BADPS,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM9B,EAAKI,QAASS,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM9B,EAAKI,QAASS,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM9B,EAAKI,QAASS,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,GAgCnE,SAASG,EAAMF,GACd,OAAKA,GACJd,EAAO,2BAA4Bc,EAAMM,SAClChB,EAAMU,KAEdT,GAAS,EAEJI,EAAM,EACHG,IAEHP,IAAUG,EAEPJ,EAAM,KAAMF,QAFpB,ICnCF,SAASmB,EAAS/B,EAASa,GAC1B,IAAId,EACAiC,EACAC,EAGJ,GADAlC,EAAO,GACFmC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMlC,EAAUC,EAAMC,GAErB,MAAMgC,EAEPC,EAAIpB,OAEJoB,EAAIjC,EAEL,IAAMmC,EAAYF,GACjB,MAAM,IAAI3B,UAAWC,EAAQ,QAAS0B,IAUvC,YARqB,IAAhBlC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ4B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIL,UAAWC,EAAQ,QAASI,IAEvC,IAAMwB,EAAYrB,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,OAAON,EAAOG,EAAY2B,EAASvC,EAAMkC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,OCvEf,SAASyB,EAAkB1B,EAAY2B,EAAStC,EAASa,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAS/B,EAAT+B,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAS/B,EAASa,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,GClB/C0B,EAAAH,EAAA,UAAAN"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index dd6f7c9..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From aae286cf7d1868c37f4786835756e29e0560ea6c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 5 Jul 2022 14:04:34 +0000 Subject: [PATCH 010/147] Auto-generated commit --- .editorconfig | 181 -- .eslintrc.js | 1 - .gitattributes | 33 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 687 ------ .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 -- .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 -- .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 ---- README.md | 47 +- benchmark/benchmark.factory.js | 73 - benchmark/benchmark.js | 160 -- branches.md | 53 - docs/repl.txt | 224 -- docs/types/test.ts | 166 -- examples/index.js | 55 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 165 -- lib/index.js | 77 - lib/limit.js | 142 -- lib/reduce_right.js | 96 - lib/validate.js | 80 - package.json | 64 +- stats.html | 2689 +++++++++++++++++++++ test/test.factory.js | 1095 --------- test/test.js | 38 - test/test.reduce_right.js | 1035 -------- test/test.validate.js | 181 -- 43 files changed, 2720 insertions(+), 6541 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/limit.js delete mode 100644 lib/reduce_right.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.reduce_right.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 7212d81..0000000 --- a/.gitattributes +++ /dev/null @@ -1,33 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1e08946..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 29bf533..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a7a7f51..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.9.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 663f5df..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 39b1613..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 7ca169c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 8 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "::set-output name=package_name::$name" - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "::set-output name=data::$data" - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v2 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v2 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 6726965..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,687 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the repository: - push: - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch or create new branch tag: - - name: 'Push changes to `deno` branch or create new branch tag' - run: | - SLUG=${{ github.repository }} - VERSION=$(echo ${{ github.ref }} | sed -E -n 's/refs\/tags\/?(v[0-9]+.[0-9]+.[0-9]+).*/\1/p') - if [ -z "$VERSION" ]; then - echo "Workflow job was not triggered by a new tag...." - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - else - echo "Workflow job was triggered by a new tag: $VERSION" - echo "Creating new bundle branch tag of the form $VERSION-deno" - git tag -a $VERSION-deno -m "$VERSION-deno" - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" $VERSION-deno - fi - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "::set-output name=alias::${alias}" - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -447,7 +446,7 @@ reduceRightAsync( files, acc, read, done ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -515,11 +514,11 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right +[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right/tree/esm -[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce +[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/tree/esm diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 46d8b83..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var reduceRightAsync; - var arr; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - reduceRightAsync = factory( onItem ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - var acc; - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 6ad0714..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var reduceRightAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=false', function benchmark( b ) { - var opts; - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'series': false - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var arr; - var len; - var acc; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'limit': 3 - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 2aded98..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right" -click B href "https://github.com/stdlib-js/utils-async-reduce-right/tree/main" -click C href "https://github.com/stdlib-js/utils-async-reduce-right/tree/production" -click D href "https://github.com/stdlib-js/utils-async-reduce-right/tree/esm" -click E href "https://github.com/stdlib-js/utils-async-reduce-right/tree/deno" -click F href "https://github.com/stdlib-js/utils-async-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right -[production-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3f22669..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,224 +0,0 @@ - -{{alias}}( collection, initial, [options,] reducer, done ) - Applies a function against an accumulator and each element in a collection - and returns the accumulated result, iterating from right to left. - - When invoked, `reducer` is provided a maximum of five arguments: - - - `accumulator`: accumulated value - - `value`: collection value - - `index`: collection index - - `collection`: the input collection - - `next`: a callback to be invoked after processing a collection `value` - - The actual number of provided arguments depends on function length. If - `reducer` accepts three arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `next` - - If `reducer` accepts four arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `index` - - `next` - - For every other `reducer` signature, `reducer` is provided all five - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `accumulator`: accumulated value - - If a provided function calls the `next` callback with a truthy `error` - argument, the function suspends execution and immediately calls the `done` - callback for subsequent `error` handling. - - Execution is *not* guaranteed to be asynchronous. To guarantee asynchrony, - 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`). - - The function does not support dynamic collection resizing. - - If provided an empty collection, the function invokes the `done` callback - with the `initial` value as the second argument. - - The function does not skip `undefined` elements. - - When processing collection elements concurrently, *beware* of race - conditions when updating an accumulator. This is especially true when an - accumulator is a primitive (e.g., a number). In general, prefer object - accumulators. - - Parameters - ---------- - collection: Array|TypedArray|Object - Input collection over which to iterate. If provided an object, the - object must be array-like (excluding strings and functions). - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - reducer: Function - The function to invoke for each element in a collection. - - done: Function - A callback invoked either upon processing all collection elements or - upon encountering an error. - - Examples - -------- - // Basic usage: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, fcn, done ) - 3000 - 2500 - 1000 - 6500 - - // Limit number of concurrent invocations: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'limit': 2 }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 2500 - 3000 - 1000 - 6500 - - // Process concurrently: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'series': false }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 1000 - 2500 - 3000 - 6500 - - -{{alias}}.factory( [options,] fcn ) - Returns a function which applies a function against an accumulator and each - element in a collection and returns the accumulated result, iterating from - right to left. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - fcn: Function - The function to invoke for each element in a collection. - - Returns - ------- - out: Function - A function which invokes a function for each element in a collection. - - Examples - -------- - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > var opts = { 'series': false }; - > var f = {{alias}}.factory( opts, fcn ); - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > f( arr, acc, done ) - 1000 - 2500 - 3000 - 6500 - > acc = { 'sum': 0 }; - > arr = [ 1000, 1500, 2000 ]; - > f( arr, acc, done ) - 1000 - 1500 - 2000 - 4500 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 143a132..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,166 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unsafe-any */ - -import reduceRightAsync = require( './index' ); - -const reducer = ( acc: any, value: number, index: number, next: Function ) => { - acc.sum += value; - if ( index === void 0 ) { - throw new Error( '`index` is missing.' ); - } - next( null, acc ); -}; - -const done = ( error: Error | null, acc: any ) => { - if ( error ) { - throw error; - } - if ( acc === void 0 ) { - throw new Error( '`acc` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( 2, acc, reducer, done ); // $ExpectError - reduceRightAsync( false, acc, reducer, done ); // $ExpectError - reduceRightAsync( true, acc, reducer, done ); // $ExpectError - reduceRightAsync( {}, acc, reducer, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a predicate argument which is not a predicate function... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 2, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, false, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, true, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 'abc', done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, [], done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a done callback argument which is not a function having a supported signature... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 2 ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, false ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, true ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 'abc' ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, {} ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, [] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const acc = { 'sum': 0 }; - reduceRightAsync(); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, reducer, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - reduceRightAsync.factory( reducer ); // $ExpectType FactoryFunction - reduceRightAsync.factory( { 'series': true }, reducer ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - reduceRightAsync.factory( [], reducer ); // $ExpectError - reduceRightAsync.factory( 123, reducer ); // $ExpectError - reduceRightAsync.factory( 'abc', reducer ); // $ExpectError - reduceRightAsync.factory( false, reducer ); // $ExpectError - reduceRightAsync.factory( true, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not a predicate function... -{ - reduceRightAsync.factory( {} ); // $ExpectError - reduceRightAsync.factory( true ); // $ExpectError - reduceRightAsync.factory( false ); // $ExpectError - reduceRightAsync.factory( {}, 123 ); // $ExpectError - reduceRightAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1( 12, acc, done ); // $ExpectError - fcn1( true, acc, done ); // $ExpectError - fcn1( false, acc, done ); // $ExpectError - fcn1( {}, acc, done ); // $ExpectError - - fcn1( [ 3000, 2500, 1000 ], acc, 12 ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, true ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, false ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, '5' ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, {} ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, [] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1(); // $ExpectError - fcn1( [ 3000, 2500, 1000 ] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - reduceRightAsync.factory( { 'limit': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': true }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': false }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - reduceRightAsync.factory( { 'series': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': 12 }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - reduceRightAsync.factory(); // $ExpectError - reduceRightAsync.factory( {}, reducer, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index dd64345..0000000 --- a/examples/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var resolve = require( 'path' ).resolve; -var readFile = require( '@stdlib/fs-read-file' ); -var reduceRightAsync = require( './../lib' ); - -var files = [ - resolve( __dirname, '..', 'package.json' ), - resolve( __dirname, '..', 'README.md' ) -]; - -function done( error, acc ) { - if ( error ) { - throw error; - } - console.log( acc.count ); -} - -function read( acc, file, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( file, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( null, acc ); - } - acc.count += 1; - next( null, acc ); - } -} - -var acc = { - 'count': 0 -}; -reduceRightAsync( files, acc, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index b19e443..9dc0658 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { Collection } from '@stdlib/types/object'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..86b95e1 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import i from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";function d(i,t){return n(t)?(o(t,"thisArg")&&(i.thisArg=t.thisArg),o(t,"series")&&(i.series=t.series,!l(i.series))?new TypeError(s("0id30","series",i.series)):o(t,"limit")&&(i.limit=t.limit,!m(i.limit))?new TypeError(s("0id3b","limit",i.limit)):null):new TypeError(s("0id2h",t))}var f=()=>{};function h(i,t,e,s,r){var n,o,l,m,d,h;if(0===(m=i.length))return r(null,t);for(l=m0&&p();function p(){function r(i,e){if(!o){if(i)return o=!0,c(i);f("Accumulator: %s",JSON.stringify(e)),t=e,c()}}f("Collection element %d: %s.",d-=1,JSON.stringify(i[d])),3===s.length?s.call(e.thisArg,t,i[d],r):4===s.length?s.call(e.thisArg,t,i[d],d,r):s.call(e.thisArg,t,i[d],d,i,r)}function c(i){return i?(f("Encountered an error: %s",i.message),r(i)):(n+=1,d>0?p():n===m?r(null,t):void 0)}}function p(i,n){var o,l,m;if(o={},arguments.length>1){if(l=d(o,i))throw l;m=n}else m=i;if(!t(m))throw new TypeError(s("0id43",m));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=r),f;function f(i,r,n){if(!e(i))throw new TypeError(s("0idBO",i));if(!t(n))throw new TypeError(s("0id43",n));return h(i,r,o,m,(function(i,t){if(i)return n(i);n(null,t)}))}}function c(i,t,e,s,r){if(arguments.length<5)return p(e)(i,t,s);p(e,s)(i,t,r)}i(c,"factory",p);export{c as default,p as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..d8d8487 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/reduce_right.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean' ;\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\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( '0id2h', 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( '0id30', '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( '0id3b', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport logger from 'debug' ;\n\n\n// VARIABLES //\n\nvar debug = logger( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function' ;\nimport isCollection from '@stdlib/assert-is-collection' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport PINF from '@stdlib/constants-float64-pinf' ;\nimport validate from './validate.js' ;\nimport limit from './limit.js' ;\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0id43', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '0idBO', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0id43', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\n* @param {Collection} collection - input collection\n* @param {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file' ;\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right' ;\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport reduceRightAsync from './reduce_right.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( reduceRightAsync, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly"],"mappings":";;y1BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUR,EAAKK,SAGnDF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASR,EAAKS,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASP,QC7BrCU,SAkBJ,SAASF,EAAOG,EAAYC,EAAKb,EAAMc,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAAa,KAHbF,EAAMP,EAAWU,QAKhB,OAAOP,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMnB,EAAKS,MACTU,EAEAnB,EAAKS,MAGZE,EAAO,0BAA2BG,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdd,EAAO,kBAAmBiB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,KA3BDhB,EAAO,6BADPS,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM9B,EAAKI,QAASS,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM9B,EAAKI,QAASS,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM9B,EAAKI,QAASS,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,GAgCnE,SAASG,EAAMF,GACd,OAAKA,GACJd,EAAO,2BAA4Bc,EAAMM,SAClChB,EAAMU,KAEdT,GAAS,EAEJI,EAAM,EACHG,IAEHP,IAAUG,EAEPJ,EAAM,KAAMF,QAFpB,ICnCF,SAASmB,EAAS/B,EAASa,GAC1B,IAAId,EACAiC,EACAC,EAGJ,GADAlC,EAAO,GACFmC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMlC,EAAUC,EAAMC,GAErB,MAAMgC,EAEPC,EAAIpB,OAEJoB,EAAIjC,EAEL,IAAMmC,EAAYF,GACjB,MAAM,IAAI3B,UAAWC,EAAQ,QAAS0B,IAUvC,YARqB,IAAhBlC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ4B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIL,UAAWC,EAAQ,QAASI,IAEvC,IAAMwB,EAAYrB,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,OAAON,EAAOG,EAAY2B,EAASvC,EAAMkC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,OCvEf,SAASyB,EAAkB1B,EAAY2B,EAAStC,EAASa,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAS/B,EAAT+B,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAS/B,EAASa,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,GClB/C0B,EAAAH,EAAA,UAAAN"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 6d67be2..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var validate = require( './validate.js' ); -var limit = require( './limit.js' ); - - -// MAIN // - -/** -* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} last argument must be a function -* @returns {Function} function which invokes the provided function once for each element in a collection -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error, data ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var opts = { -* 'series': false -* }; -* -* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: -* var reduceRightAsync = factory( opts, read ); -* -* // Create a collection over which to iterate: -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* // Define a callback which handles errors: -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* // Run `read` for each element in `files`: -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, done ); -*/ -function factory( options, fcn ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = fcn; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '0id43', f ) ); - } - if ( opts.series === void 0 && opts.limit === void 0 ) { - opts.series = true; - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return reduceRightAsync; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * @private - * @param {Collection} collection - input collection - * @param {*} initial - initial value - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be a collection - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function reduceRightAsync( collection, initial, done ) { - if ( !isCollection( collection ) ) { - throw new TypeError( format( '0idBO', collection ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '0id43', done ) ); - } - return limit( collection, initial, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {*} [acc] - accumulated value - * @returns {void} - */ - function clbk( error, acc ) { - if ( error ) { - return done( error ); - } - done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 84aeb69..0000000 --- a/lib/index.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* @module @stdlib/utils-async-reduce-right -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' ); -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var reduceRightAsync = require( './reduce_right.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( reduceRightAsync, 'factory', factory ); - - -// EXPORTS // - -module.exports = reduceRightAsync; diff --git a/lib/limit.js b/lib/limit.js deleted file mode 100644 index cdb60af..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); - - -// VARIABLES // - -var debug = logger( 'reduce-right-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each element in a collection, limiting the number of concurrently pending functions and iterating from right to left. -* -* @private -* @param {Collection} collection - input collection -* @param {*} acc - initial value -* @param {Options} opts - function options -* @param {*} [opts.thisArg] - execution context -* @param {PositiveInteger} [opts.limit] - maximum number of pending function invocations -* @param {Function} fcn - function to invoke -* @param {Callback} done - function to invoke upon completion or upon encountering an error -* @returns {void} -*/ -function limit( collection, acc, opts, fcn, done ) { - var count; - var flg; - var lim; - var len; - var idx; - var i; - - len = collection.length; - debug( 'Collection length: %d', len ); - - if ( len === 0 ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - count = 0; - idx = len; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all collection elements... - if ( idx > 0 ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next element in a collection. - * - * @private - */ - function next() { - idx -= 1; - debug( 'Collection element %d: %s.', idx, JSON.stringify( collection[ idx ] ) ); - if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], cb ); - } else if ( fcn.length === 4 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, cb ); - } else { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len - } - /** - * Callback invoked once a provided function finishes processing a collection element. - * - * @private - * @param {*} [error] - error - * @param {*} [result] - accumulation result - * @returns {void} - */ - function cb( error, result ) { - if ( flg ) { - // Prevent further processing of collection elements: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Accumulator: %s', JSON.stringify( result ) ); - acc = result; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next collection element. - * - * @private - * @param {*} [error] - error - * @returns {void} - */ - function clbk( error ) { - if ( error ) { - debug( 'Encountered an error: %s', error.message ); - return done( error ); - } - count += 1; - debug( 'Processed %d of %d collection elements.', count, len ); - if ( idx > 0 ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/reduce_right.js b/lib/reduce_right.js deleted file mode 100644 index 9f016bf..0000000 --- a/lib/reduce_right.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param {Collection} collection - input collection -* @param {*} initial - initial value -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} second-to-last argument must be a function -* @throws {TypeError} last argument must be a function -* @returns {void} -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -function reduceRightAsync( collection, initial, options, fcn, done ) { - if ( arguments.length < 5 ) { - return factory( options )( collection, initial, fcn ); - } - factory( options, fcn )( collection, initial, done ); -} - - -// EXPORTS // - -module.exports = reduceRightAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 6292663..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @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 -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'thisArg': {}, -* 'series': false, -* 'limit': 10 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '0id2h', options ) ); - } - if ( hasOwnProp( options, 'thisArg' ) ) { - opts.thisArg = options.thisArg; - } - if ( hasOwnProp( options, 'series' ) ) { - opts.series = options.series; - if ( !isBoolean( opts.series ) ) { - return new TypeError( format( '0id30', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '0id3b', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 005e6d8..55f16d9 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.8", "description": "Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,43 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-boolean": "^0.0.x", - "@stdlib/assert-is-collection": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/assert-is-positive-integer": "^0.0.x", - "@stdlib/constants-float64-pinf": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/constants-float64-eps": "^0.0.x", - "@stdlib/fs-read-file": "^0.0.x", - "@stdlib/utils-noop": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..52a3a90 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 8244931..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1095 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( {}, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, next ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - factory( opts, next ); - }; - } -}); - -tape( 'the function returns a function (no options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided a collection (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a collection (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (1 argument)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (2 arguments)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with five arguments', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn() { - var value; - var next; - var acc; - var k; - - acc = arguments[ 0 ]; - value = arguments[ 1 ]; - k = arguments[ 2 ]; - next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( k, i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the returned function supports processing collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements concurrently', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 100, 250, 300 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements sequentially (limit = 1)', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of collection elements which are processed at any one time', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 250, 300, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 250, 100, 300 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var reduceRightAsync; - var arr; - - reduceRightAsync = factory( fcn ); - arr = []; - - reduceRightAsync( arr, 0, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var reduceRightAsync; - var obj; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = []; - obj = {}; - reduceRightAsync( arr, obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - i = 0; - - reduceRightAsync( arr, {}, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, acc ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the returned function does not skip empty elements', function test( t ) { - var reduceRightAsync; - var expected; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index f273a40..0000000 --- a/test/test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof reduceRightAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.reduce_right.js b/test/test.reduce_right.js deleted file mode 100644 index dc3e5d5..0000000 --- a/test/test.reduce_right.js +++ /dev/null @@ -1,1035 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var reduceRightAsync = require( './../lib/reduce_right.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a collection', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (no options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, next, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, 0 ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - reduceRightAsync( [ 1, 2, 3 ], 0, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (1 argument)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (2 arguments)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with five arguments', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn() { - var next; - var acc; - var v; - - next = arguments[ 4 ]; - acc = arguments[ 0 ]; - v = arguments[ 1 ]; - - i -= 1; - j += 1; - - t.strictEqual( v, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, v ); - - function onTimeout() { - acc.sum += v; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'by default, the function processes collection elements sequentially', function test( t ) { - var values; - var count; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements concurrently', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 100, 250, 300 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': true - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially (limit = 1)', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var arr; - var ctx; - - arr = [ 3, 2, 1 ]; - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 3, 2, 1 ]; - opts = { - 'series': true - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 250, 100, 300 ]; - opts = { - 'limit': 2 - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var arr = []; - reduceRightAsync( arr, 0, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var arr = []; - var obj = {}; - - reduceRightAsync( arr, obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - arr = [ 3, 2, 1 ]; - i = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, value ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the function does not skip empty elements', function test( t ) { - var expected; - var arr; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, fcn, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 7660838..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,181 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `limit` option which is not a positive integer', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - -5, - 0, - 3.14, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'limit': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `series` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'series': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function accepts any value for the `thisArg` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'thisArg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err, null, 'returns null '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'thisArg': {}, - 'series': false, - 'limit': 10 - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From 58ea6499fe84890a8e2a13ef349f0a0539f0c4de Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 6 Jul 2022 15:38:22 +0000 Subject: [PATCH 011/147] Transform error messages --- lib/factory.js | 8 ++++---- lib/validate.js | 8 ++++---- package.json | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index a627d69..6d67be2 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -22,7 +22,7 @@ var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var PINF = require( '@stdlib/constants-float64-pinf' ); var validate = require( './validate.js' ); var limit = require( './limit.js' ); @@ -110,7 +110,7 @@ function factory( options, fcn ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '0id43', f ) ); } if ( opts.series === void 0 && opts.limit === void 0 ) { opts.series = true; @@ -135,10 +135,10 @@ function factory( options, fcn ) { */ function reduceRightAsync( collection, initial, done ) { if ( !isCollection( collection ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a collection. Value: `%s`.', collection ) ); + throw new TypeError( format( '0idBO', collection ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '0id43', done ) ); } return limit( collection, initial, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index 9ba927e..6292663 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,7 +54,7 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0id2h', options ) ); } if ( hasOwnProp( options, 'thisArg' ) ) { opts.thisArg = options.thisArg; @@ -62,13 +62,13 @@ function validate( opts, options ) { if ( hasOwnProp( options, 'series' ) ) { opts.series = options.series; if ( !isBoolean( opts.series ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'series', opts.series ) ); + return new TypeError( format( '0id30', 'series', opts.series ) ); } } if ( hasOwnProp( options, 'limit' ) ) { opts.limit = options.limit; if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'limit', opts.limit ) ); + return new TypeError( format( '0id3b', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index fb48f96..005e6d8 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-plain-object": "^0.0.x", "@stdlib/assert-is-positive-integer": "^0.0.x", "@stdlib/constants-float64-pinf": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x", "debug": "^2.6.9" From d39a71890d845fd0050881eb210f4a4fe585fb39 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 6 Jul 2022 15:38:58 +0000 Subject: [PATCH 012/147] Remove files --- index.d.ts | 415 -------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 3109 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 9dc0658..0000000 --- a/index.d.ts +++ /dev/null @@ -1,415 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Collection } from '@stdlib/types/object'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * The maximum number of pending invocations at any one time. - */ - limit?: number; - - /** - * Boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection (default: true). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback function. -*/ -type Nullary = () => void; - -/** -* Callback function. -* -* @param error - encountered error or null -*/ -type Unary = ( error: Error | null ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Binary = ( error: Error | null, accumulator: any ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param next - a callback to be invoked after processing a collection `value` -*/ -type TernaryReducer = ( accumulator: any, value: any, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuaternaryReducer = ( accumulator: any, value: any, index: number, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuinaryReducer = ( accumulator: any, value: any, index: number, collection: Collection, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type Reducer = TernaryReducer | QuaternaryReducer | QuinaryReducer; - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result. -* -* @param collection - input collection -* @param initial - initial value -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( collection: Collection, initial: any, done: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Interface for `reduceRightAsync`. -*/ -interface ReduceRightAsync { - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, {}, read, done ); - */ - ( collection: Collection, initial: any, options: Options, reducer: Reducer, done: Callback ): void; // tslint-disable-line max-line-length - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, read, done ); - */ - ( collection: Collection, initial: any, reducer: Reducer, done: Callback ): void; // tslint-disable-line max-line-length - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @throws must provide valid options - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var opts = { - * 'series': false - * }; - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( opts, read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( options: Options, reducer: Reducer ): FactoryFunction; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param reducer - function to invoke for each element in a collection - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( reducer: Reducer ): FactoryFunction; -} - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param collection - input collection -* @param initial - initial value -* @param options - function options -* @param options.thisArg - execution context -* @param options.limit - maximum number of pending invocations at any one time -* @param 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 (default: true) -* @param reducer - function to invoke for each element in a collection -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( `@stdlib/fs/read-file` ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -declare var reduceRightAsync: ReduceRightAsync; - - -// EXPORTS // - -export = reduceRightAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 86b95e1..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import i from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";function d(i,t){return n(t)?(o(t,"thisArg")&&(i.thisArg=t.thisArg),o(t,"series")&&(i.series=t.series,!l(i.series))?new TypeError(s("0id30","series",i.series)):o(t,"limit")&&(i.limit=t.limit,!m(i.limit))?new TypeError(s("0id3b","limit",i.limit)):null):new TypeError(s("0id2h",t))}var f=()=>{};function h(i,t,e,s,r){var n,o,l,m,d,h;if(0===(m=i.length))return r(null,t);for(l=m0&&p();function p(){function r(i,e){if(!o){if(i)return o=!0,c(i);f("Accumulator: %s",JSON.stringify(e)),t=e,c()}}f("Collection element %d: %s.",d-=1,JSON.stringify(i[d])),3===s.length?s.call(e.thisArg,t,i[d],r):4===s.length?s.call(e.thisArg,t,i[d],d,r):s.call(e.thisArg,t,i[d],d,i,r)}function c(i){return i?(f("Encountered an error: %s",i.message),r(i)):(n+=1,d>0?p():n===m?r(null,t):void 0)}}function p(i,n){var o,l,m;if(o={},arguments.length>1){if(l=d(o,i))throw l;m=n}else m=i;if(!t(m))throw new TypeError(s("0id43",m));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=r),f;function f(i,r,n){if(!e(i))throw new TypeError(s("0idBO",i));if(!t(n))throw new TypeError(s("0id43",n));return h(i,r,o,m,(function(i,t){if(i)return n(i);n(null,t)}))}}function c(i,t,e,s,r){if(arguments.length<5)return p(e)(i,t,s);p(e,s)(i,t,r)}i(c,"factory",p);export{c as default,p as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index d8d8487..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/reduce_right.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean' ;\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\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( '0id2h', 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( '0id30', '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( '0id3b', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport logger from 'debug' ;\n\n\n// VARIABLES //\n\nvar debug = logger( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function' ;\nimport isCollection from '@stdlib/assert-is-collection' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport PINF from '@stdlib/constants-float64-pinf' ;\nimport validate from './validate.js' ;\nimport limit from './limit.js' ;\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0id43', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '0idBO', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0id43', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\n* @param {Collection} collection - input collection\n* @param {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file' ;\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right' ;\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport reduceRightAsync from './reduce_right.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( reduceRightAsync, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly"],"mappings":";;y1BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUR,EAAKK,SAGnDF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASR,EAAKS,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASP,QC7BrCU,SAkBJ,SAASF,EAAOG,EAAYC,EAAKb,EAAMc,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAAa,KAHbF,EAAMP,EAAWU,QAKhB,OAAOP,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMnB,EAAKS,MACTU,EAEAnB,EAAKS,MAGZE,EAAO,0BAA2BG,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdd,EAAO,kBAAmBiB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,KA3BDhB,EAAO,6BADPS,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM9B,EAAKI,QAASS,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM9B,EAAKI,QAASS,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM9B,EAAKI,QAASS,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,GAgCnE,SAASG,EAAMF,GACd,OAAKA,GACJd,EAAO,2BAA4Bc,EAAMM,SAClChB,EAAMU,KAEdT,GAAS,EAEJI,EAAM,EACHG,IAEHP,IAAUG,EAEPJ,EAAM,KAAMF,QAFpB,ICnCF,SAASmB,EAAS/B,EAASa,GAC1B,IAAId,EACAiC,EACAC,EAGJ,GADAlC,EAAO,GACFmC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMlC,EAAUC,EAAMC,GAErB,MAAMgC,EAEPC,EAAIpB,OAEJoB,EAAIjC,EAEL,IAAMmC,EAAYF,GACjB,MAAM,IAAI3B,UAAWC,EAAQ,QAAS0B,IAUvC,YARqB,IAAhBlC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ4B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIL,UAAWC,EAAQ,QAASI,IAEvC,IAAMwB,EAAYrB,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,OAAON,EAAOG,EAAY2B,EAASvC,EAAMkC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,OCvEf,SAASyB,EAAkB1B,EAAY2B,EAAStC,EAASa,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAS/B,EAAT+B,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAS/B,EAASa,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,GClB/C0B,EAAAH,EAAA,UAAAN"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 52a3a90..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 5cdbdfb005d0185d37f4f92518ae9f9e814afa23 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 6 Jul 2022 15:39:37 +0000 Subject: [PATCH 013/147] Auto-generated commit --- .editorconfig | 181 -- .eslintrc.js | 1 - .gitattributes | 33 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 687 ------ .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 -- .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 -- .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 ---- README.md | 47 +- benchmark/benchmark.factory.js | 73 - benchmark/benchmark.js | 160 -- branches.md | 53 - docs/repl.txt | 224 -- docs/types/test.ts | 166 -- examples/index.js | 55 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 165 -- lib/index.js | 77 - lib/limit.js | 142 -- lib/reduce_right.js | 96 - lib/validate.js | 80 - package.json | 64 +- stats.html | 2689 +++++++++++++++++++++ test/test.factory.js | 1095 --------- test/test.js | 38 - test/test.reduce_right.js | 1035 -------- test/test.validate.js | 181 -- 44 files changed, 2720 insertions(+), 6542 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/limit.js delete mode 100644 lib/reduce_right.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.reduce_right.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 7212d81..0000000 --- a/.gitattributes +++ /dev/null @@ -1,33 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 8b13789..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ - diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1e08946..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 29bf533..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a7a7f51..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.9.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 663f5df..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 39b1613..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 7ca169c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 8 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "::set-output name=package_name::$name" - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "::set-output name=data::$data" - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v2 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v2 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 6726965..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,687 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the repository: - push: - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch or create new branch tag: - - name: 'Push changes to `deno` branch or create new branch tag' - run: | - SLUG=${{ github.repository }} - VERSION=$(echo ${{ github.ref }} | sed -E -n 's/refs\/tags\/?(v[0-9]+.[0-9]+.[0-9]+).*/\1/p') - if [ -z "$VERSION" ]; then - echo "Workflow job was not triggered by a new tag...." - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - else - echo "Workflow job was triggered by a new tag: $VERSION" - echo "Creating new bundle branch tag of the form $VERSION-deno" - git tag -a $VERSION-deno -m "$VERSION-deno" - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" $VERSION-deno - fi - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "::set-output name=alias::${alias}" - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -447,7 +446,7 @@ reduceRightAsync( files, acc, read, done ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -515,11 +514,11 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right +[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right/tree/esm -[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce +[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/tree/esm diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 46d8b83..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var reduceRightAsync; - var arr; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - reduceRightAsync = factory( onItem ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - var acc; - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 6ad0714..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var reduceRightAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=false', function benchmark( b ) { - var opts; - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'series': false - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var arr; - var len; - var acc; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'limit': 3 - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 2aded98..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right" -click B href "https://github.com/stdlib-js/utils-async-reduce-right/tree/main" -click C href "https://github.com/stdlib-js/utils-async-reduce-right/tree/production" -click D href "https://github.com/stdlib-js/utils-async-reduce-right/tree/esm" -click E href "https://github.com/stdlib-js/utils-async-reduce-right/tree/deno" -click F href "https://github.com/stdlib-js/utils-async-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right -[production-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3f22669..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,224 +0,0 @@ - -{{alias}}( collection, initial, [options,] reducer, done ) - Applies a function against an accumulator and each element in a collection - and returns the accumulated result, iterating from right to left. - - When invoked, `reducer` is provided a maximum of five arguments: - - - `accumulator`: accumulated value - - `value`: collection value - - `index`: collection index - - `collection`: the input collection - - `next`: a callback to be invoked after processing a collection `value` - - The actual number of provided arguments depends on function length. If - `reducer` accepts three arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `next` - - If `reducer` accepts four arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `index` - - `next` - - For every other `reducer` signature, `reducer` is provided all five - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `accumulator`: accumulated value - - If a provided function calls the `next` callback with a truthy `error` - argument, the function suspends execution and immediately calls the `done` - callback for subsequent `error` handling. - - Execution is *not* guaranteed to be asynchronous. To guarantee asynchrony, - 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`). - - The function does not support dynamic collection resizing. - - If provided an empty collection, the function invokes the `done` callback - with the `initial` value as the second argument. - - The function does not skip `undefined` elements. - - When processing collection elements concurrently, *beware* of race - conditions when updating an accumulator. This is especially true when an - accumulator is a primitive (e.g., a number). In general, prefer object - accumulators. - - Parameters - ---------- - collection: Array|TypedArray|Object - Input collection over which to iterate. If provided an object, the - object must be array-like (excluding strings and functions). - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - reducer: Function - The function to invoke for each element in a collection. - - done: Function - A callback invoked either upon processing all collection elements or - upon encountering an error. - - Examples - -------- - // Basic usage: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, fcn, done ) - 3000 - 2500 - 1000 - 6500 - - // Limit number of concurrent invocations: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'limit': 2 }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 2500 - 3000 - 1000 - 6500 - - // Process concurrently: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'series': false }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 1000 - 2500 - 3000 - 6500 - - -{{alias}}.factory( [options,] fcn ) - Returns a function which applies a function against an accumulator and each - element in a collection and returns the accumulated result, iterating from - right to left. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - fcn: Function - The function to invoke for each element in a collection. - - Returns - ------- - out: Function - A function which invokes a function for each element in a collection. - - Examples - -------- - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > var opts = { 'series': false }; - > var f = {{alias}}.factory( opts, fcn ); - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > f( arr, acc, done ) - 1000 - 2500 - 3000 - 6500 - > acc = { 'sum': 0 }; - > arr = [ 1000, 1500, 2000 ]; - > f( arr, acc, done ) - 1000 - 1500 - 2000 - 4500 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 143a132..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,166 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unsafe-any */ - -import reduceRightAsync = require( './index' ); - -const reducer = ( acc: any, value: number, index: number, next: Function ) => { - acc.sum += value; - if ( index === void 0 ) { - throw new Error( '`index` is missing.' ); - } - next( null, acc ); -}; - -const done = ( error: Error | null, acc: any ) => { - if ( error ) { - throw error; - } - if ( acc === void 0 ) { - throw new Error( '`acc` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( 2, acc, reducer, done ); // $ExpectError - reduceRightAsync( false, acc, reducer, done ); // $ExpectError - reduceRightAsync( true, acc, reducer, done ); // $ExpectError - reduceRightAsync( {}, acc, reducer, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a predicate argument which is not a predicate function... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 2, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, false, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, true, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 'abc', done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, [], done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a done callback argument which is not a function having a supported signature... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 2 ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, false ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, true ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 'abc' ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, {} ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, [] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const acc = { 'sum': 0 }; - reduceRightAsync(); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, reducer, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - reduceRightAsync.factory( reducer ); // $ExpectType FactoryFunction - reduceRightAsync.factory( { 'series': true }, reducer ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - reduceRightAsync.factory( [], reducer ); // $ExpectError - reduceRightAsync.factory( 123, reducer ); // $ExpectError - reduceRightAsync.factory( 'abc', reducer ); // $ExpectError - reduceRightAsync.factory( false, reducer ); // $ExpectError - reduceRightAsync.factory( true, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not a predicate function... -{ - reduceRightAsync.factory( {} ); // $ExpectError - reduceRightAsync.factory( true ); // $ExpectError - reduceRightAsync.factory( false ); // $ExpectError - reduceRightAsync.factory( {}, 123 ); // $ExpectError - reduceRightAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1( 12, acc, done ); // $ExpectError - fcn1( true, acc, done ); // $ExpectError - fcn1( false, acc, done ); // $ExpectError - fcn1( {}, acc, done ); // $ExpectError - - fcn1( [ 3000, 2500, 1000 ], acc, 12 ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, true ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, false ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, '5' ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, {} ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, [] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1(); // $ExpectError - fcn1( [ 3000, 2500, 1000 ] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - reduceRightAsync.factory( { 'limit': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': true }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': false }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - reduceRightAsync.factory( { 'series': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': 12 }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - reduceRightAsync.factory(); // $ExpectError - reduceRightAsync.factory( {}, reducer, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index dd64345..0000000 --- a/examples/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var resolve = require( 'path' ).resolve; -var readFile = require( '@stdlib/fs-read-file' ); -var reduceRightAsync = require( './../lib' ); - -var files = [ - resolve( __dirname, '..', 'package.json' ), - resolve( __dirname, '..', 'README.md' ) -]; - -function done( error, acc ) { - if ( error ) { - throw error; - } - console.log( acc.count ); -} - -function read( acc, file, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( file, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( null, acc ); - } - acc.count += 1; - next( null, acc ); - } -} - -var acc = { - 'count': 0 -}; -reduceRightAsync( files, acc, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index b19e443..9dc0658 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { Collection } from '@stdlib/types/object'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..86b95e1 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import i from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";function d(i,t){return n(t)?(o(t,"thisArg")&&(i.thisArg=t.thisArg),o(t,"series")&&(i.series=t.series,!l(i.series))?new TypeError(s("0id30","series",i.series)):o(t,"limit")&&(i.limit=t.limit,!m(i.limit))?new TypeError(s("0id3b","limit",i.limit)):null):new TypeError(s("0id2h",t))}var f=()=>{};function h(i,t,e,s,r){var n,o,l,m,d,h;if(0===(m=i.length))return r(null,t);for(l=m0&&p();function p(){function r(i,e){if(!o){if(i)return o=!0,c(i);f("Accumulator: %s",JSON.stringify(e)),t=e,c()}}f("Collection element %d: %s.",d-=1,JSON.stringify(i[d])),3===s.length?s.call(e.thisArg,t,i[d],r):4===s.length?s.call(e.thisArg,t,i[d],d,r):s.call(e.thisArg,t,i[d],d,i,r)}function c(i){return i?(f("Encountered an error: %s",i.message),r(i)):(n+=1,d>0?p():n===m?r(null,t):void 0)}}function p(i,n){var o,l,m;if(o={},arguments.length>1){if(l=d(o,i))throw l;m=n}else m=i;if(!t(m))throw new TypeError(s("0id43",m));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=r),f;function f(i,r,n){if(!e(i))throw new TypeError(s("0idBO",i));if(!t(n))throw new TypeError(s("0id43",n));return h(i,r,o,m,(function(i,t){if(i)return n(i);n(null,t)}))}}function c(i,t,e,s,r){if(arguments.length<5)return p(e)(i,t,s);p(e,s)(i,t,r)}i(c,"factory",p);export{c as default,p as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..d8d8487 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/reduce_right.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean' ;\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\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( '0id2h', 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( '0id30', '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( '0id3b', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport logger from 'debug' ;\n\n\n// VARIABLES //\n\nvar debug = logger( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function' ;\nimport isCollection from '@stdlib/assert-is-collection' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport PINF from '@stdlib/constants-float64-pinf' ;\nimport validate from './validate.js' ;\nimport limit from './limit.js' ;\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0id43', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '0idBO', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0id43', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\n* @param {Collection} collection - input collection\n* @param {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file' ;\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right' ;\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport reduceRightAsync from './reduce_right.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( reduceRightAsync, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly"],"mappings":";;y1BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUR,EAAKK,SAGnDF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASR,EAAKS,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASP,QC7BrCU,SAkBJ,SAASF,EAAOG,EAAYC,EAAKb,EAAMc,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAAa,KAHbF,EAAMP,EAAWU,QAKhB,OAAOP,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMnB,EAAKS,MACTU,EAEAnB,EAAKS,MAGZE,EAAO,0BAA2BG,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdd,EAAO,kBAAmBiB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,KA3BDhB,EAAO,6BADPS,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM9B,EAAKI,QAASS,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM9B,EAAKI,QAASS,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM9B,EAAKI,QAASS,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,GAgCnE,SAASG,EAAMF,GACd,OAAKA,GACJd,EAAO,2BAA4Bc,EAAMM,SAClChB,EAAMU,KAEdT,GAAS,EAEJI,EAAM,EACHG,IAEHP,IAAUG,EAEPJ,EAAM,KAAMF,QAFpB,ICnCF,SAASmB,EAAS/B,EAASa,GAC1B,IAAId,EACAiC,EACAC,EAGJ,GADAlC,EAAO,GACFmC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMlC,EAAUC,EAAMC,GAErB,MAAMgC,EAEPC,EAAIpB,OAEJoB,EAAIjC,EAEL,IAAMmC,EAAYF,GACjB,MAAM,IAAI3B,UAAWC,EAAQ,QAAS0B,IAUvC,YARqB,IAAhBlC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ4B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIL,UAAWC,EAAQ,QAASI,IAEvC,IAAMwB,EAAYrB,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,OAAON,EAAOG,EAAY2B,EAASvC,EAAMkC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,OCvEf,SAASyB,EAAkB1B,EAAY2B,EAAStC,EAASa,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAS/B,EAAT+B,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAS/B,EAASa,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,GClB/C0B,EAAAH,EAAA,UAAAN"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 6d67be2..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var validate = require( './validate.js' ); -var limit = require( './limit.js' ); - - -// MAIN // - -/** -* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} last argument must be a function -* @returns {Function} function which invokes the provided function once for each element in a collection -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error, data ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var opts = { -* 'series': false -* }; -* -* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: -* var reduceRightAsync = factory( opts, read ); -* -* // Create a collection over which to iterate: -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* // Define a callback which handles errors: -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* // Run `read` for each element in `files`: -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, done ); -*/ -function factory( options, fcn ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = fcn; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '0id43', f ) ); - } - if ( opts.series === void 0 && opts.limit === void 0 ) { - opts.series = true; - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return reduceRightAsync; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * @private - * @param {Collection} collection - input collection - * @param {*} initial - initial value - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be a collection - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function reduceRightAsync( collection, initial, done ) { - if ( !isCollection( collection ) ) { - throw new TypeError( format( '0idBO', collection ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '0id43', done ) ); - } - return limit( collection, initial, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {*} [acc] - accumulated value - * @returns {void} - */ - function clbk( error, acc ) { - if ( error ) { - return done( error ); - } - done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 84aeb69..0000000 --- a/lib/index.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* @module @stdlib/utils-async-reduce-right -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' ); -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var reduceRightAsync = require( './reduce_right.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( reduceRightAsync, 'factory', factory ); - - -// EXPORTS // - -module.exports = reduceRightAsync; diff --git a/lib/limit.js b/lib/limit.js deleted file mode 100644 index cdb60af..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); - - -// VARIABLES // - -var debug = logger( 'reduce-right-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each element in a collection, limiting the number of concurrently pending functions and iterating from right to left. -* -* @private -* @param {Collection} collection - input collection -* @param {*} acc - initial value -* @param {Options} opts - function options -* @param {*} [opts.thisArg] - execution context -* @param {PositiveInteger} [opts.limit] - maximum number of pending function invocations -* @param {Function} fcn - function to invoke -* @param {Callback} done - function to invoke upon completion or upon encountering an error -* @returns {void} -*/ -function limit( collection, acc, opts, fcn, done ) { - var count; - var flg; - var lim; - var len; - var idx; - var i; - - len = collection.length; - debug( 'Collection length: %d', len ); - - if ( len === 0 ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - count = 0; - idx = len; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all collection elements... - if ( idx > 0 ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next element in a collection. - * - * @private - */ - function next() { - idx -= 1; - debug( 'Collection element %d: %s.', idx, JSON.stringify( collection[ idx ] ) ); - if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], cb ); - } else if ( fcn.length === 4 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, cb ); - } else { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len - } - /** - * Callback invoked once a provided function finishes processing a collection element. - * - * @private - * @param {*} [error] - error - * @param {*} [result] - accumulation result - * @returns {void} - */ - function cb( error, result ) { - if ( flg ) { - // Prevent further processing of collection elements: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Accumulator: %s', JSON.stringify( result ) ); - acc = result; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next collection element. - * - * @private - * @param {*} [error] - error - * @returns {void} - */ - function clbk( error ) { - if ( error ) { - debug( 'Encountered an error: %s', error.message ); - return done( error ); - } - count += 1; - debug( 'Processed %d of %d collection elements.', count, len ); - if ( idx > 0 ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/reduce_right.js b/lib/reduce_right.js deleted file mode 100644 index 9f016bf..0000000 --- a/lib/reduce_right.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param {Collection} collection - input collection -* @param {*} initial - initial value -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} second-to-last argument must be a function -* @throws {TypeError} last argument must be a function -* @returns {void} -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -function reduceRightAsync( collection, initial, options, fcn, done ) { - if ( arguments.length < 5 ) { - return factory( options )( collection, initial, fcn ); - } - factory( options, fcn )( collection, initial, done ); -} - - -// EXPORTS // - -module.exports = reduceRightAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 6292663..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @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 -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'thisArg': {}, -* 'series': false, -* 'limit': 10 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '0id2h', options ) ); - } - if ( hasOwnProp( options, 'thisArg' ) ) { - opts.thisArg = options.thisArg; - } - if ( hasOwnProp( options, 'series' ) ) { - opts.series = options.series; - if ( !isBoolean( opts.series ) ) { - return new TypeError( format( '0id30', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '0id3b', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 005e6d8..55f16d9 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.8", "description": "Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,43 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-boolean": "^0.0.x", - "@stdlib/assert-is-collection": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/assert-is-positive-integer": "^0.0.x", - "@stdlib/constants-float64-pinf": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/constants-float64-eps": "^0.0.x", - "@stdlib/fs-read-file": "^0.0.x", - "@stdlib/utils-noop": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a21f4c2 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 8244931..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1095 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( {}, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, next ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - factory( opts, next ); - }; - } -}); - -tape( 'the function returns a function (no options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided a collection (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a collection (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (1 argument)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (2 arguments)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with five arguments', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn() { - var value; - var next; - var acc; - var k; - - acc = arguments[ 0 ]; - value = arguments[ 1 ]; - k = arguments[ 2 ]; - next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( k, i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the returned function supports processing collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements concurrently', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 100, 250, 300 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements sequentially (limit = 1)', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of collection elements which are processed at any one time', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 250, 300, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 250, 100, 300 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var reduceRightAsync; - var arr; - - reduceRightAsync = factory( fcn ); - arr = []; - - reduceRightAsync( arr, 0, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var reduceRightAsync; - var obj; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = []; - obj = {}; - reduceRightAsync( arr, obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - i = 0; - - reduceRightAsync( arr, {}, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, acc ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the returned function does not skip empty elements', function test( t ) { - var reduceRightAsync; - var expected; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index f273a40..0000000 --- a/test/test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof reduceRightAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.reduce_right.js b/test/test.reduce_right.js deleted file mode 100644 index dc3e5d5..0000000 --- a/test/test.reduce_right.js +++ /dev/null @@ -1,1035 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var reduceRightAsync = require( './../lib/reduce_right.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a collection', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (no options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, next, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, 0 ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - reduceRightAsync( [ 1, 2, 3 ], 0, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (1 argument)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (2 arguments)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with five arguments', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn() { - var next; - var acc; - var v; - - next = arguments[ 4 ]; - acc = arguments[ 0 ]; - v = arguments[ 1 ]; - - i -= 1; - j += 1; - - t.strictEqual( v, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, v ); - - function onTimeout() { - acc.sum += v; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'by default, the function processes collection elements sequentially', function test( t ) { - var values; - var count; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements concurrently', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 100, 250, 300 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': true - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially (limit = 1)', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var arr; - var ctx; - - arr = [ 3, 2, 1 ]; - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 3, 2, 1 ]; - opts = { - 'series': true - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 250, 100, 300 ]; - opts = { - 'limit': 2 - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var arr = []; - reduceRightAsync( arr, 0, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var arr = []; - var obj = {}; - - reduceRightAsync( arr, obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - arr = [ 3, 2, 1 ]; - i = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, value ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the function does not skip empty elements', function test( t ) { - var expected; - var arr; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, fcn, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 7660838..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,181 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `limit` option which is not a positive integer', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - -5, - 0, - 3.14, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'limit': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `series` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'series': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function accepts any value for the `thisArg` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'thisArg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err, null, 'returns null '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'thisArg': {}, - 'series': false, - 'limit': 10 - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From 70a46a120439e0af8458fccc02a31a9a08253881 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 03:50:24 +0000 Subject: [PATCH 014/147] Transform error messages --- lib/factory.js | 8 ++++---- lib/validate.js | 8 ++++---- package.json | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index a627d69..6d67be2 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -22,7 +22,7 @@ var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var PINF = require( '@stdlib/constants-float64-pinf' ); var validate = require( './validate.js' ); var limit = require( './limit.js' ); @@ -110,7 +110,7 @@ function factory( options, fcn ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '0id43', f ) ); } if ( opts.series === void 0 && opts.limit === void 0 ) { opts.series = true; @@ -135,10 +135,10 @@ function factory( options, fcn ) { */ function reduceRightAsync( collection, initial, done ) { if ( !isCollection( collection ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a collection. Value: `%s`.', collection ) ); + throw new TypeError( format( '0idBO', collection ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '0id43', done ) ); } return limit( collection, initial, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index 9ba927e..6292663 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,7 +54,7 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0id2h', options ) ); } if ( hasOwnProp( options, 'thisArg' ) ) { opts.thisArg = options.thisArg; @@ -62,13 +62,13 @@ function validate( opts, options ) { if ( hasOwnProp( options, 'series' ) ) { opts.series = options.series; if ( !isBoolean( opts.series ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'series', opts.series ) ); + return new TypeError( format( '0id30', 'series', opts.series ) ); } } if ( hasOwnProp( options, 'limit' ) ) { opts.limit = options.limit; if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'limit', opts.limit ) ); + return new TypeError( format( '0id3b', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index fb48f96..005e6d8 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-plain-object": "^0.0.x", "@stdlib/assert-is-positive-integer": "^0.0.x", "@stdlib/constants-float64-pinf": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x", "debug": "^2.6.9" From 176552eb8a4ddd9c5b77dc6f0375ea71035e6e97 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 14:24:49 +0000 Subject: [PATCH 015/147] Remove files --- index.d.ts | 415 -------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 3109 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 9dc0658..0000000 --- a/index.d.ts +++ /dev/null @@ -1,415 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Collection } from '@stdlib/types/object'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * The maximum number of pending invocations at any one time. - */ - limit?: number; - - /** - * Boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection (default: true). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback function. -*/ -type Nullary = () => void; - -/** -* Callback function. -* -* @param error - encountered error or null -*/ -type Unary = ( error: Error | null ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Binary = ( error: Error | null, accumulator: any ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param next - a callback to be invoked after processing a collection `value` -*/ -type TernaryReducer = ( accumulator: any, value: any, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuaternaryReducer = ( accumulator: any, value: any, index: number, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuinaryReducer = ( accumulator: any, value: any, index: number, collection: Collection, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type Reducer = TernaryReducer | QuaternaryReducer | QuinaryReducer; - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result. -* -* @param collection - input collection -* @param initial - initial value -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( collection: Collection, initial: any, done: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Interface for `reduceRightAsync`. -*/ -interface ReduceRightAsync { - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, {}, read, done ); - */ - ( collection: Collection, initial: any, options: Options, reducer: Reducer, done: Callback ): void; // tslint-disable-line max-line-length - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, read, done ); - */ - ( collection: Collection, initial: any, reducer: Reducer, done: Callback ): void; // tslint-disable-line max-line-length - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @throws must provide valid options - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var opts = { - * 'series': false - * }; - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( opts, read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( options: Options, reducer: Reducer ): FactoryFunction; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param reducer - function to invoke for each element in a collection - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( reducer: Reducer ): FactoryFunction; -} - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param collection - input collection -* @param initial - initial value -* @param options - function options -* @param options.thisArg - execution context -* @param options.limit - maximum number of pending invocations at any one time -* @param 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 (default: true) -* @param reducer - function to invoke for each element in a collection -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( `@stdlib/fs/read-file` ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -declare var reduceRightAsync: ReduceRightAsync; - - -// EXPORTS // - -export = reduceRightAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 86b95e1..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import i from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";function d(i,t){return n(t)?(o(t,"thisArg")&&(i.thisArg=t.thisArg),o(t,"series")&&(i.series=t.series,!l(i.series))?new TypeError(s("0id30","series",i.series)):o(t,"limit")&&(i.limit=t.limit,!m(i.limit))?new TypeError(s("0id3b","limit",i.limit)):null):new TypeError(s("0id2h",t))}var f=()=>{};function h(i,t,e,s,r){var n,o,l,m,d,h;if(0===(m=i.length))return r(null,t);for(l=m0&&p();function p(){function r(i,e){if(!o){if(i)return o=!0,c(i);f("Accumulator: %s",JSON.stringify(e)),t=e,c()}}f("Collection element %d: %s.",d-=1,JSON.stringify(i[d])),3===s.length?s.call(e.thisArg,t,i[d],r):4===s.length?s.call(e.thisArg,t,i[d],d,r):s.call(e.thisArg,t,i[d],d,i,r)}function c(i){return i?(f("Encountered an error: %s",i.message),r(i)):(n+=1,d>0?p():n===m?r(null,t):void 0)}}function p(i,n){var o,l,m;if(o={},arguments.length>1){if(l=d(o,i))throw l;m=n}else m=i;if(!t(m))throw new TypeError(s("0id43",m));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=r),f;function f(i,r,n){if(!e(i))throw new TypeError(s("0idBO",i));if(!t(n))throw new TypeError(s("0id43",n));return h(i,r,o,m,(function(i,t){if(i)return n(i);n(null,t)}))}}function c(i,t,e,s,r){if(arguments.length<5)return p(e)(i,t,s);p(e,s)(i,t,r)}i(c,"factory",p);export{c as default,p as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index d8d8487..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/reduce_right.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean' ;\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\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( '0id2h', 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( '0id30', '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( '0id3b', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport logger from 'debug' ;\n\n\n// VARIABLES //\n\nvar debug = logger( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function' ;\nimport isCollection from '@stdlib/assert-is-collection' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport PINF from '@stdlib/constants-float64-pinf' ;\nimport validate from './validate.js' ;\nimport limit from './limit.js' ;\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0id43', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '0idBO', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0id43', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\n* @param {Collection} collection - input collection\n* @param {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file' ;\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right' ;\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport reduceRightAsync from './reduce_right.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( reduceRightAsync, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly"],"mappings":";;y1BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUR,EAAKK,SAGnDF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASR,EAAKS,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASP,QC7BrCU,SAkBJ,SAASF,EAAOG,EAAYC,EAAKb,EAAMc,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAAa,KAHbF,EAAMP,EAAWU,QAKhB,OAAOP,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMnB,EAAKS,MACTU,EAEAnB,EAAKS,MAGZE,EAAO,0BAA2BG,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdd,EAAO,kBAAmBiB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,KA3BDhB,EAAO,6BADPS,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM9B,EAAKI,QAASS,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM9B,EAAKI,QAASS,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM9B,EAAKI,QAASS,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,GAgCnE,SAASG,EAAMF,GACd,OAAKA,GACJd,EAAO,2BAA4Bc,EAAMM,SAClChB,EAAMU,KAEdT,GAAS,EAEJI,EAAM,EACHG,IAEHP,IAAUG,EAEPJ,EAAM,KAAMF,QAFpB,ICnCF,SAASmB,EAAS/B,EAASa,GAC1B,IAAId,EACAiC,EACAC,EAGJ,GADAlC,EAAO,GACFmC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMlC,EAAUC,EAAMC,GAErB,MAAMgC,EAEPC,EAAIpB,OAEJoB,EAAIjC,EAEL,IAAMmC,EAAYF,GACjB,MAAM,IAAI3B,UAAWC,EAAQ,QAAS0B,IAUvC,YARqB,IAAhBlC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ4B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIL,UAAWC,EAAQ,QAASI,IAEvC,IAAMwB,EAAYrB,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,OAAON,EAAOG,EAAY2B,EAASvC,EAAMkC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,OCvEf,SAASyB,EAAkB1B,EAAY2B,EAAStC,EAASa,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAS/B,EAAT+B,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAS/B,EAASa,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,GClB/C0B,EAAAH,EAAA,UAAAN"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index a21f4c2..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From e05fef307ea2079241b40fedbf5d61b35cc0b710 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 14:25:34 +0000 Subject: [PATCH 016/147] Auto-generated commit --- .editorconfig | 181 -- .eslintrc.js | 1 - .gitattributes | 33 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 760 ------ .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 -- .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 -- .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 ---- README.md | 47 +- benchmark/benchmark.factory.js | 73 - benchmark/benchmark.js | 160 -- branches.md | 53 - docs/repl.txt | 224 -- docs/types/test.ts | 166 -- examples/index.js | 55 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 165 -- lib/index.js | 77 - lib/limit.js | 142 -- lib/reduce_right.js | 96 - lib/validate.js | 80 - package.json | 64 +- stats.html | 2689 +++++++++++++++++++++ test/test.factory.js | 1095 --------- test/test.js | 38 - test/test.reduce_right.js | 1035 -------- test/test.validate.js | 181 -- 44 files changed, 2720 insertions(+), 6615 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/limit.js delete mode 100644 lib/reduce_right.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.reduce_right.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 7212d81..0000000 --- a/.gitattributes +++ /dev/null @@ -1,33 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index f9562e5..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-08-01T01:11:49.882Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1e08946..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 29bf533..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a7a7f51..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.9.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 663f5df..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 39b1613..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 7ca169c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 8 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "::set-output name=package_name::$name" - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "::set-output name=data::$data" - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v2 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v2 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 5094681..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,760 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "::set-output name=alias::${alias}" - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -447,7 +446,7 @@ reduceRightAsync( files, acc, read, done ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -515,11 +514,11 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right +[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right/tree/esm -[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce +[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/tree/esm diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 46d8b83..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var reduceRightAsync; - var arr; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - reduceRightAsync = factory( onItem ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - var acc; - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 6ad0714..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var reduceRightAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=false', function benchmark( b ) { - var opts; - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'series': false - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var arr; - var len; - var acc; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'limit': 3 - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 2aded98..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right" -click B href "https://github.com/stdlib-js/utils-async-reduce-right/tree/main" -click C href "https://github.com/stdlib-js/utils-async-reduce-right/tree/production" -click D href "https://github.com/stdlib-js/utils-async-reduce-right/tree/esm" -click E href "https://github.com/stdlib-js/utils-async-reduce-right/tree/deno" -click F href "https://github.com/stdlib-js/utils-async-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right -[production-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3f22669..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,224 +0,0 @@ - -{{alias}}( collection, initial, [options,] reducer, done ) - Applies a function against an accumulator and each element in a collection - and returns the accumulated result, iterating from right to left. - - When invoked, `reducer` is provided a maximum of five arguments: - - - `accumulator`: accumulated value - - `value`: collection value - - `index`: collection index - - `collection`: the input collection - - `next`: a callback to be invoked after processing a collection `value` - - The actual number of provided arguments depends on function length. If - `reducer` accepts three arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `next` - - If `reducer` accepts four arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `index` - - `next` - - For every other `reducer` signature, `reducer` is provided all five - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `accumulator`: accumulated value - - If a provided function calls the `next` callback with a truthy `error` - argument, the function suspends execution and immediately calls the `done` - callback for subsequent `error` handling. - - Execution is *not* guaranteed to be asynchronous. To guarantee asynchrony, - 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`). - - The function does not support dynamic collection resizing. - - If provided an empty collection, the function invokes the `done` callback - with the `initial` value as the second argument. - - The function does not skip `undefined` elements. - - When processing collection elements concurrently, *beware* of race - conditions when updating an accumulator. This is especially true when an - accumulator is a primitive (e.g., a number). In general, prefer object - accumulators. - - Parameters - ---------- - collection: Array|TypedArray|Object - Input collection over which to iterate. If provided an object, the - object must be array-like (excluding strings and functions). - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - reducer: Function - The function to invoke for each element in a collection. - - done: Function - A callback invoked either upon processing all collection elements or - upon encountering an error. - - Examples - -------- - // Basic usage: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, fcn, done ) - 3000 - 2500 - 1000 - 6500 - - // Limit number of concurrent invocations: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'limit': 2 }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 2500 - 3000 - 1000 - 6500 - - // Process concurrently: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'series': false }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 1000 - 2500 - 3000 - 6500 - - -{{alias}}.factory( [options,] fcn ) - Returns a function which applies a function against an accumulator and each - element in a collection and returns the accumulated result, iterating from - right to left. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - fcn: Function - The function to invoke for each element in a collection. - - Returns - ------- - out: Function - A function which invokes a function for each element in a collection. - - Examples - -------- - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > var opts = { 'series': false }; - > var f = {{alias}}.factory( opts, fcn ); - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > f( arr, acc, done ) - 1000 - 2500 - 3000 - 6500 - > acc = { 'sum': 0 }; - > arr = [ 1000, 1500, 2000 ]; - > f( arr, acc, done ) - 1000 - 1500 - 2000 - 4500 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 143a132..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,166 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unsafe-any */ - -import reduceRightAsync = require( './index' ); - -const reducer = ( acc: any, value: number, index: number, next: Function ) => { - acc.sum += value; - if ( index === void 0 ) { - throw new Error( '`index` is missing.' ); - } - next( null, acc ); -}; - -const done = ( error: Error | null, acc: any ) => { - if ( error ) { - throw error; - } - if ( acc === void 0 ) { - throw new Error( '`acc` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( 2, acc, reducer, done ); // $ExpectError - reduceRightAsync( false, acc, reducer, done ); // $ExpectError - reduceRightAsync( true, acc, reducer, done ); // $ExpectError - reduceRightAsync( {}, acc, reducer, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a predicate argument which is not a predicate function... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 2, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, false, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, true, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 'abc', done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, [], done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a done callback argument which is not a function having a supported signature... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 2 ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, false ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, true ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 'abc' ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, {} ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, [] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const acc = { 'sum': 0 }; - reduceRightAsync(); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, reducer, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - reduceRightAsync.factory( reducer ); // $ExpectType FactoryFunction - reduceRightAsync.factory( { 'series': true }, reducer ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - reduceRightAsync.factory( [], reducer ); // $ExpectError - reduceRightAsync.factory( 123, reducer ); // $ExpectError - reduceRightAsync.factory( 'abc', reducer ); // $ExpectError - reduceRightAsync.factory( false, reducer ); // $ExpectError - reduceRightAsync.factory( true, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not a predicate function... -{ - reduceRightAsync.factory( {} ); // $ExpectError - reduceRightAsync.factory( true ); // $ExpectError - reduceRightAsync.factory( false ); // $ExpectError - reduceRightAsync.factory( {}, 123 ); // $ExpectError - reduceRightAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1( 12, acc, done ); // $ExpectError - fcn1( true, acc, done ); // $ExpectError - fcn1( false, acc, done ); // $ExpectError - fcn1( {}, acc, done ); // $ExpectError - - fcn1( [ 3000, 2500, 1000 ], acc, 12 ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, true ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, false ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, '5' ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, {} ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, [] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1(); // $ExpectError - fcn1( [ 3000, 2500, 1000 ] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - reduceRightAsync.factory( { 'limit': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': true }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': false }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - reduceRightAsync.factory( { 'series': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': 12 }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - reduceRightAsync.factory(); // $ExpectError - reduceRightAsync.factory( {}, reducer, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index dd64345..0000000 --- a/examples/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var resolve = require( 'path' ).resolve; -var readFile = require( '@stdlib/fs-read-file' ); -var reduceRightAsync = require( './../lib' ); - -var files = [ - resolve( __dirname, '..', 'package.json' ), - resolve( __dirname, '..', 'README.md' ) -]; - -function done( error, acc ) { - if ( error ) { - throw error; - } - console.log( acc.count ); -} - -function read( acc, file, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( file, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( null, acc ); - } - acc.count += 1; - next( null, acc ); - } -} - -var acc = { - 'count': 0 -}; -reduceRightAsync( files, acc, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index b19e443..9dc0658 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { Collection } from '@stdlib/types/object'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..228c429 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import i from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";function d(i,t){return n(t)?(o(t,"thisArg")&&(i.thisArg=t.thisArg),o(t,"series")&&(i.series=t.series,!l(i.series))?new TypeError(s("0id30","series",i.series)):o(t,"limit")&&(i.limit=t.limit,!m(i.limit))?new TypeError(s("0id3b","limit",i.limit)):null):new TypeError(s("0id2h",t))}var f=()=>{};function h(i,t,e,s,r){var n,o,l,m,d,h;if(0===(m=i.length))return r(null,t);for(l=m0&&p();function p(){function r(i,e){if(!o){if(i)return o=!0,c(i);f("Accumulator: %s",JSON.stringify(e)),t=e,c()}}f("Collection element %d: %s.",d-=1,JSON.stringify(i[d])),3===s.length?s.call(e.thisArg,t,i[d],r):4===s.length?s.call(e.thisArg,t,i[d],d,r):s.call(e.thisArg,t,i[d],d,i,r)}function c(i){return i?(f("Encountered an error: %s",i.message),r(i)):(n+=1,d>0?p():n===m?r(null,t):void 0)}}function p(i,n){var o,l,m;if(o={},arguments.length>1){if(l=d(o,i))throw l;m=n}else m=i;if(!t(m))throw new TypeError(s("0id43",m));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=r),f;function f(i,r,n){if(!e(i))throw new TypeError(s("0idBO",i));if(!t(n))throw new TypeError(s("0id43",n));return h(i,r,o,m,(function(i,t){if(i)return n(i);n(null,t)}))}}function c(i,t,e,s,r){if(arguments.length<5)return p(e)(i,t,s);p(e,s)(i,t,r)}i(c,"factory",p);export{c as default,p as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..e8a1458 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/reduce_right.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean' ;\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\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( '0id2h', 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( '0id30', '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( '0id3b', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport logger from 'debug' ;\n\n\n// VARIABLES //\n\nvar debug = logger( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function' ;\nimport isCollection from '@stdlib/assert-is-collection' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport PINF from '@stdlib/constants-float64-pinf' ;\nimport validate from './validate.js' ;\nimport limit from './limit.js' ;\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0id43', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '0idBO', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0id43', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\n* @param {Collection} collection - input collection\n* @param {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file' ;\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right' ;\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport reduceRightAsync from './reduce_right.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( reduceRightAsync, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly"],"mappings":";;g2BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUR,EAAKK,SAGnDF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASR,EAAKS,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASP,QC7BrCU,SAkBJ,SAASF,EAAOG,EAAYC,EAAKb,EAAMc,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAAa,KAHbF,EAAMP,EAAWU,QAKhB,OAAOP,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMnB,EAAKS,MACTU,EAEAnB,EAAKS,MAGZE,EAAO,0BAA2BG,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdd,EAAO,kBAAmBiB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,KA3BDhB,EAAO,6BADPS,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM9B,EAAKI,QAASS,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM9B,EAAKI,QAASS,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM9B,EAAKI,QAASS,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,GAgCnE,SAASG,EAAMF,GACd,OAAKA,GACJd,EAAO,2BAA4Bc,EAAMM,SAClChB,EAAMU,KAEdT,GAAS,EAEJI,EAAM,EACHG,IAEHP,IAAUG,EAEPJ,EAAM,KAAMF,QAFpB,ICnCF,SAASmB,EAAS/B,EAASa,GAC1B,IAAId,EACAiC,EACAC,EAGJ,GADAlC,EAAO,GACFmC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMlC,EAAUC,EAAMC,GAErB,MAAMgC,EAEPC,EAAIpB,OAEJoB,EAAIjC,EAEL,IAAMmC,EAAYF,GACjB,MAAM,IAAI3B,UAAWC,EAAQ,QAAS0B,IAUvC,YARqB,IAAhBlC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ4B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIL,UAAWC,EAAQ,QAASI,IAEvC,IAAMwB,EAAYrB,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,OAAON,EAAOG,EAAY2B,EAASvC,EAAMkC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,OCvEf,SAASyB,EAAkB1B,EAAY2B,EAAStC,EAASa,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAS/B,EAAT+B,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAS/B,EAASa,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,GClB/C0B,EAAAH,EAAA,UAAAN"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 6d67be2..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var validate = require( './validate.js' ); -var limit = require( './limit.js' ); - - -// MAIN // - -/** -* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} last argument must be a function -* @returns {Function} function which invokes the provided function once for each element in a collection -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error, data ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var opts = { -* 'series': false -* }; -* -* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: -* var reduceRightAsync = factory( opts, read ); -* -* // Create a collection over which to iterate: -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* // Define a callback which handles errors: -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* // Run `read` for each element in `files`: -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, done ); -*/ -function factory( options, fcn ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = fcn; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '0id43', f ) ); - } - if ( opts.series === void 0 && opts.limit === void 0 ) { - opts.series = true; - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return reduceRightAsync; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * @private - * @param {Collection} collection - input collection - * @param {*} initial - initial value - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be a collection - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function reduceRightAsync( collection, initial, done ) { - if ( !isCollection( collection ) ) { - throw new TypeError( format( '0idBO', collection ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '0id43', done ) ); - } - return limit( collection, initial, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {*} [acc] - accumulated value - * @returns {void} - */ - function clbk( error, acc ) { - if ( error ) { - return done( error ); - } - done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 84aeb69..0000000 --- a/lib/index.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* @module @stdlib/utils-async-reduce-right -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' ); -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var reduceRightAsync = require( './reduce_right.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( reduceRightAsync, 'factory', factory ); - - -// EXPORTS // - -module.exports = reduceRightAsync; diff --git a/lib/limit.js b/lib/limit.js deleted file mode 100644 index cdb60af..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); - - -// VARIABLES // - -var debug = logger( 'reduce-right-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each element in a collection, limiting the number of concurrently pending functions and iterating from right to left. -* -* @private -* @param {Collection} collection - input collection -* @param {*} acc - initial value -* @param {Options} opts - function options -* @param {*} [opts.thisArg] - execution context -* @param {PositiveInteger} [opts.limit] - maximum number of pending function invocations -* @param {Function} fcn - function to invoke -* @param {Callback} done - function to invoke upon completion or upon encountering an error -* @returns {void} -*/ -function limit( collection, acc, opts, fcn, done ) { - var count; - var flg; - var lim; - var len; - var idx; - var i; - - len = collection.length; - debug( 'Collection length: %d', len ); - - if ( len === 0 ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - count = 0; - idx = len; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all collection elements... - if ( idx > 0 ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next element in a collection. - * - * @private - */ - function next() { - idx -= 1; - debug( 'Collection element %d: %s.', idx, JSON.stringify( collection[ idx ] ) ); - if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], cb ); - } else if ( fcn.length === 4 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, cb ); - } else { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len - } - /** - * Callback invoked once a provided function finishes processing a collection element. - * - * @private - * @param {*} [error] - error - * @param {*} [result] - accumulation result - * @returns {void} - */ - function cb( error, result ) { - if ( flg ) { - // Prevent further processing of collection elements: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Accumulator: %s', JSON.stringify( result ) ); - acc = result; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next collection element. - * - * @private - * @param {*} [error] - error - * @returns {void} - */ - function clbk( error ) { - if ( error ) { - debug( 'Encountered an error: %s', error.message ); - return done( error ); - } - count += 1; - debug( 'Processed %d of %d collection elements.', count, len ); - if ( idx > 0 ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/reduce_right.js b/lib/reduce_right.js deleted file mode 100644 index 9f016bf..0000000 --- a/lib/reduce_right.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param {Collection} collection - input collection -* @param {*} initial - initial value -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} second-to-last argument must be a function -* @throws {TypeError} last argument must be a function -* @returns {void} -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -function reduceRightAsync( collection, initial, options, fcn, done ) { - if ( arguments.length < 5 ) { - return factory( options )( collection, initial, fcn ); - } - factory( options, fcn )( collection, initial, done ); -} - - -// EXPORTS // - -module.exports = reduceRightAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 6292663..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @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 -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'thisArg': {}, -* 'series': false, -* 'limit': 10 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '0id2h', options ) ); - } - if ( hasOwnProp( options, 'thisArg' ) ) { - opts.thisArg = options.thisArg; - } - if ( hasOwnProp( options, 'series' ) ) { - opts.series = options.series; - if ( !isBoolean( opts.series ) ) { - return new TypeError( format( '0id30', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '0id3b', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 005e6d8..55f16d9 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.8", "description": "Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,43 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-boolean": "^0.0.x", - "@stdlib/assert-is-collection": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/assert-is-positive-integer": "^0.0.x", - "@stdlib/constants-float64-pinf": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/constants-float64-eps": "^0.0.x", - "@stdlib/fs-read-file": "^0.0.x", - "@stdlib/utils-noop": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..7cc4af7 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 8244931..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1095 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( {}, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, next ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - factory( opts, next ); - }; - } -}); - -tape( 'the function returns a function (no options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided a collection (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a collection (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (1 argument)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (2 arguments)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with five arguments', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn() { - var value; - var next; - var acc; - var k; - - acc = arguments[ 0 ]; - value = arguments[ 1 ]; - k = arguments[ 2 ]; - next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( k, i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the returned function supports processing collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements concurrently', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 100, 250, 300 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements sequentially (limit = 1)', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of collection elements which are processed at any one time', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 250, 300, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 250, 100, 300 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var reduceRightAsync; - var arr; - - reduceRightAsync = factory( fcn ); - arr = []; - - reduceRightAsync( arr, 0, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var reduceRightAsync; - var obj; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = []; - obj = {}; - reduceRightAsync( arr, obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - i = 0; - - reduceRightAsync( arr, {}, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, acc ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the returned function does not skip empty elements', function test( t ) { - var reduceRightAsync; - var expected; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index f273a40..0000000 --- a/test/test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof reduceRightAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.reduce_right.js b/test/test.reduce_right.js deleted file mode 100644 index dc3e5d5..0000000 --- a/test/test.reduce_right.js +++ /dev/null @@ -1,1035 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var reduceRightAsync = require( './../lib/reduce_right.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a collection', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (no options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, next, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, 0 ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - reduceRightAsync( [ 1, 2, 3 ], 0, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (1 argument)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (2 arguments)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with five arguments', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn() { - var next; - var acc; - var v; - - next = arguments[ 4 ]; - acc = arguments[ 0 ]; - v = arguments[ 1 ]; - - i -= 1; - j += 1; - - t.strictEqual( v, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, v ); - - function onTimeout() { - acc.sum += v; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'by default, the function processes collection elements sequentially', function test( t ) { - var values; - var count; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements concurrently', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 100, 250, 300 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': true - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially (limit = 1)', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var arr; - var ctx; - - arr = [ 3, 2, 1 ]; - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 3, 2, 1 ]; - opts = { - 'series': true - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 250, 100, 300 ]; - opts = { - 'limit': 2 - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var arr = []; - reduceRightAsync( arr, 0, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var arr = []; - var obj = {}; - - reduceRightAsync( arr, obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - arr = [ 3, 2, 1 ]; - i = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, value ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the function does not skip empty elements', function test( t ) { - var expected; - var arr; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, fcn, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 7660838..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,181 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `limit` option which is not a positive integer', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - -5, - 0, - 3.14, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'limit': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `series` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'series': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function accepts any value for the `thisArg` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'thisArg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err, null, 'returns null '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'thisArg': {}, - 'series': false, - 'limit': 10 - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From 4a2efa7f5f8fbcca1cc184fd191404a325d32822 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 03:39:59 +0000 Subject: [PATCH 017/147] Transform error messages --- lib/factory.js | 8 ++++---- lib/validate.js | 8 ++++---- package.json | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index a627d69..6d67be2 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -22,7 +22,7 @@ var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var PINF = require( '@stdlib/constants-float64-pinf' ); var validate = require( './validate.js' ); var limit = require( './limit.js' ); @@ -110,7 +110,7 @@ function factory( options, fcn ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '0id43', f ) ); } if ( opts.series === void 0 && opts.limit === void 0 ) { opts.series = true; @@ -135,10 +135,10 @@ function factory( options, fcn ) { */ function reduceRightAsync( collection, initial, done ) { if ( !isCollection( collection ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a collection. Value: `%s`.', collection ) ); + throw new TypeError( format( '0idBO', collection ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '0id43', done ) ); } return limit( collection, initial, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index 9ba927e..6292663 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,7 +54,7 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0id2h', options ) ); } if ( hasOwnProp( options, 'thisArg' ) ) { opts.thisArg = options.thisArg; @@ -62,13 +62,13 @@ function validate( opts, options ) { if ( hasOwnProp( options, 'series' ) ) { opts.series = options.series; if ( !isBoolean( opts.series ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'series', opts.series ) ); + return new TypeError( format( '0id30', 'series', opts.series ) ); } } if ( hasOwnProp( options, 'limit' ) ) { opts.limit = options.limit; if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'limit', opts.limit ) ); + return new TypeError( format( '0id3b', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index fb48f96..005e6d8 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-plain-object": "^0.0.x", "@stdlib/assert-is-positive-integer": "^0.0.x", "@stdlib/constants-float64-pinf": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x", "debug": "^2.6.9" From f253a4f6fae4b67dad71bf13817078d32e59de04 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 13:52:24 +0000 Subject: [PATCH 018/147] Remove files --- index.d.ts | 415 -------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 3109 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 9dc0658..0000000 --- a/index.d.ts +++ /dev/null @@ -1,415 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Collection } from '@stdlib/types/object'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * The maximum number of pending invocations at any one time. - */ - limit?: number; - - /** - * Boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection (default: true). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback function. -*/ -type Nullary = () => void; - -/** -* Callback function. -* -* @param error - encountered error or null -*/ -type Unary = ( error: Error | null ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Binary = ( error: Error | null, accumulator: any ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param next - a callback to be invoked after processing a collection `value` -*/ -type TernaryReducer = ( accumulator: any, value: any, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuaternaryReducer = ( accumulator: any, value: any, index: number, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuinaryReducer = ( accumulator: any, value: any, index: number, collection: Collection, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type Reducer = TernaryReducer | QuaternaryReducer | QuinaryReducer; - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result. -* -* @param collection - input collection -* @param initial - initial value -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( collection: Collection, initial: any, done: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Interface for `reduceRightAsync`. -*/ -interface ReduceRightAsync { - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, {}, read, done ); - */ - ( collection: Collection, initial: any, options: Options, reducer: Reducer, done: Callback ): void; // tslint-disable-line max-line-length - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, read, done ); - */ - ( collection: Collection, initial: any, reducer: Reducer, done: Callback ): void; // tslint-disable-line max-line-length - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @throws must provide valid options - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var opts = { - * 'series': false - * }; - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( opts, read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( options: Options, reducer: Reducer ): FactoryFunction; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param reducer - function to invoke for each element in a collection - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( reducer: Reducer ): FactoryFunction; -} - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param collection - input collection -* @param initial - initial value -* @param options - function options -* @param options.thisArg - execution context -* @param options.limit - maximum number of pending invocations at any one time -* @param 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 (default: true) -* @param reducer - function to invoke for each element in a collection -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( `@stdlib/fs/read-file` ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -declare var reduceRightAsync: ReduceRightAsync; - - -// EXPORTS // - -export = reduceRightAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 228c429..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import i from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";function d(i,t){return n(t)?(o(t,"thisArg")&&(i.thisArg=t.thisArg),o(t,"series")&&(i.series=t.series,!l(i.series))?new TypeError(s("0id30","series",i.series)):o(t,"limit")&&(i.limit=t.limit,!m(i.limit))?new TypeError(s("0id3b","limit",i.limit)):null):new TypeError(s("0id2h",t))}var f=()=>{};function h(i,t,e,s,r){var n,o,l,m,d,h;if(0===(m=i.length))return r(null,t);for(l=m0&&p();function p(){function r(i,e){if(!o){if(i)return o=!0,c(i);f("Accumulator: %s",JSON.stringify(e)),t=e,c()}}f("Collection element %d: %s.",d-=1,JSON.stringify(i[d])),3===s.length?s.call(e.thisArg,t,i[d],r):4===s.length?s.call(e.thisArg,t,i[d],d,r):s.call(e.thisArg,t,i[d],d,i,r)}function c(i){return i?(f("Encountered an error: %s",i.message),r(i)):(n+=1,d>0?p():n===m?r(null,t):void 0)}}function p(i,n){var o,l,m;if(o={},arguments.length>1){if(l=d(o,i))throw l;m=n}else m=i;if(!t(m))throw new TypeError(s("0id43",m));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=r),f;function f(i,r,n){if(!e(i))throw new TypeError(s("0idBO",i));if(!t(n))throw new TypeError(s("0id43",n));return h(i,r,o,m,(function(i,t){if(i)return n(i);n(null,t)}))}}function c(i,t,e,s,r){if(arguments.length<5)return p(e)(i,t,s);p(e,s)(i,t,r)}i(c,"factory",p);export{c as default,p as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index e8a1458..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/reduce_right.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean' ;\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\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( '0id2h', 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( '0id30', '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( '0id3b', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport logger from 'debug' ;\n\n\n// VARIABLES //\n\nvar debug = logger( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function' ;\nimport isCollection from '@stdlib/assert-is-collection' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport PINF from '@stdlib/constants-float64-pinf' ;\nimport validate from './validate.js' ;\nimport limit from './limit.js' ;\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0id43', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '0idBO', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0id43', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\n* @param {Collection} collection - input collection\n* @param {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file' ;\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right' ;\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport reduceRightAsync from './reduce_right.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( reduceRightAsync, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly"],"mappings":";;g2BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUR,EAAKK,SAGnDF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASR,EAAKS,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASP,QC7BrCU,SAkBJ,SAASF,EAAOG,EAAYC,EAAKb,EAAMc,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAAa,KAHbF,EAAMP,EAAWU,QAKhB,OAAOP,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMnB,EAAKS,MACTU,EAEAnB,EAAKS,MAGZE,EAAO,0BAA2BG,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdd,EAAO,kBAAmBiB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,KA3BDhB,EAAO,6BADPS,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM9B,EAAKI,QAASS,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM9B,EAAKI,QAASS,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM9B,EAAKI,QAASS,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,GAgCnE,SAASG,EAAMF,GACd,OAAKA,GACJd,EAAO,2BAA4Bc,EAAMM,SAClChB,EAAMU,KAEdT,GAAS,EAEJI,EAAM,EACHG,IAEHP,IAAUG,EAEPJ,EAAM,KAAMF,QAFpB,ICnCF,SAASmB,EAAS/B,EAASa,GAC1B,IAAId,EACAiC,EACAC,EAGJ,GADAlC,EAAO,GACFmC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMlC,EAAUC,EAAMC,GAErB,MAAMgC,EAEPC,EAAIpB,OAEJoB,EAAIjC,EAEL,IAAMmC,EAAYF,GACjB,MAAM,IAAI3B,UAAWC,EAAQ,QAAS0B,IAUvC,YARqB,IAAhBlC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ4B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIL,UAAWC,EAAQ,QAASI,IAEvC,IAAMwB,EAAYrB,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,OAAON,EAAOG,EAAY2B,EAASvC,EAAMkC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,OCvEf,SAASyB,EAAkB1B,EAAY2B,EAAStC,EAASa,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAS/B,EAAT+B,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAS/B,EAASa,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,GClB/C0B,EAAAH,EAAA,UAAAN"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 7cc4af7..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From c42d730290b03d81ec2f4f3f1118f097381e1c36 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 13:53:04 +0000 Subject: [PATCH 019/147] Auto-generated commit --- .editorconfig | 181 -- .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 760 ------ .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 -- .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 -- .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 ---- README.md | 47 +- benchmark/benchmark.factory.js | 73 - benchmark/benchmark.js | 160 -- branches.md | 53 - docs/repl.txt | 224 -- docs/types/test.ts | 166 -- examples/index.js | 55 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 165 -- lib/index.js | 77 - lib/limit.js | 142 -- lib/reduce_right.js | 96 - lib/validate.js | 80 - package.json | 64 +- stats.html | 2689 +++++++++++++++++++++ test/test.factory.js | 1095 --------- test/test.js | 38 - test/test.reduce_right.js | 1035 -------- test/test.validate.js | 181 -- 44 files changed, 2720 insertions(+), 6631 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/limit.js delete mode 100644 lib/reduce_right.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.reduce_right.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 096d599..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-09-01T01:09:33.618Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1e08946..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 29bf533..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a7a7f51..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.9.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 663f5df..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 39b1613..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 7ca169c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 8 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "::set-output name=package_name::$name" - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "::set-output name=data::$data" - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v2 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v2 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 5094681..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,760 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "::set-output name=alias::${alias}" - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -447,7 +446,7 @@ reduceRightAsync( files, acc, read, done ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -515,11 +514,11 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right +[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right/tree/esm -[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce +[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/tree/esm diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 46d8b83..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var reduceRightAsync; - var arr; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - reduceRightAsync = factory( onItem ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - var acc; - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 6ad0714..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var reduceRightAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=false', function benchmark( b ) { - var opts; - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'series': false - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var arr; - var len; - var acc; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'limit': 3 - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 2aded98..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right" -click B href "https://github.com/stdlib-js/utils-async-reduce-right/tree/main" -click C href "https://github.com/stdlib-js/utils-async-reduce-right/tree/production" -click D href "https://github.com/stdlib-js/utils-async-reduce-right/tree/esm" -click E href "https://github.com/stdlib-js/utils-async-reduce-right/tree/deno" -click F href "https://github.com/stdlib-js/utils-async-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right -[production-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3f22669..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,224 +0,0 @@ - -{{alias}}( collection, initial, [options,] reducer, done ) - Applies a function against an accumulator and each element in a collection - and returns the accumulated result, iterating from right to left. - - When invoked, `reducer` is provided a maximum of five arguments: - - - `accumulator`: accumulated value - - `value`: collection value - - `index`: collection index - - `collection`: the input collection - - `next`: a callback to be invoked after processing a collection `value` - - The actual number of provided arguments depends on function length. If - `reducer` accepts three arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `next` - - If `reducer` accepts four arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `index` - - `next` - - For every other `reducer` signature, `reducer` is provided all five - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `accumulator`: accumulated value - - If a provided function calls the `next` callback with a truthy `error` - argument, the function suspends execution and immediately calls the `done` - callback for subsequent `error` handling. - - Execution is *not* guaranteed to be asynchronous. To guarantee asynchrony, - 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`). - - The function does not support dynamic collection resizing. - - If provided an empty collection, the function invokes the `done` callback - with the `initial` value as the second argument. - - The function does not skip `undefined` elements. - - When processing collection elements concurrently, *beware* of race - conditions when updating an accumulator. This is especially true when an - accumulator is a primitive (e.g., a number). In general, prefer object - accumulators. - - Parameters - ---------- - collection: Array|TypedArray|Object - Input collection over which to iterate. If provided an object, the - object must be array-like (excluding strings and functions). - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - reducer: Function - The function to invoke for each element in a collection. - - done: Function - A callback invoked either upon processing all collection elements or - upon encountering an error. - - Examples - -------- - // Basic usage: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, fcn, done ) - 3000 - 2500 - 1000 - 6500 - - // Limit number of concurrent invocations: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'limit': 2 }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 2500 - 3000 - 1000 - 6500 - - // Process concurrently: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'series': false }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 1000 - 2500 - 3000 - 6500 - - -{{alias}}.factory( [options,] fcn ) - Returns a function which applies a function against an accumulator and each - element in a collection and returns the accumulated result, iterating from - right to left. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - fcn: Function - The function to invoke for each element in a collection. - - Returns - ------- - out: Function - A function which invokes a function for each element in a collection. - - Examples - -------- - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > var opts = { 'series': false }; - > var f = {{alias}}.factory( opts, fcn ); - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > f( arr, acc, done ) - 1000 - 2500 - 3000 - 6500 - > acc = { 'sum': 0 }; - > arr = [ 1000, 1500, 2000 ]; - > f( arr, acc, done ) - 1000 - 1500 - 2000 - 4500 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 143a132..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,166 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unsafe-any */ - -import reduceRightAsync = require( './index' ); - -const reducer = ( acc: any, value: number, index: number, next: Function ) => { - acc.sum += value; - if ( index === void 0 ) { - throw new Error( '`index` is missing.' ); - } - next( null, acc ); -}; - -const done = ( error: Error | null, acc: any ) => { - if ( error ) { - throw error; - } - if ( acc === void 0 ) { - throw new Error( '`acc` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( 2, acc, reducer, done ); // $ExpectError - reduceRightAsync( false, acc, reducer, done ); // $ExpectError - reduceRightAsync( true, acc, reducer, done ); // $ExpectError - reduceRightAsync( {}, acc, reducer, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a predicate argument which is not a predicate function... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 2, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, false, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, true, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 'abc', done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, [], done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a done callback argument which is not a function having a supported signature... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 2 ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, false ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, true ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 'abc' ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, {} ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, [] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const acc = { 'sum': 0 }; - reduceRightAsync(); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, reducer, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - reduceRightAsync.factory( reducer ); // $ExpectType FactoryFunction - reduceRightAsync.factory( { 'series': true }, reducer ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - reduceRightAsync.factory( [], reducer ); // $ExpectError - reduceRightAsync.factory( 123, reducer ); // $ExpectError - reduceRightAsync.factory( 'abc', reducer ); // $ExpectError - reduceRightAsync.factory( false, reducer ); // $ExpectError - reduceRightAsync.factory( true, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not a predicate function... -{ - reduceRightAsync.factory( {} ); // $ExpectError - reduceRightAsync.factory( true ); // $ExpectError - reduceRightAsync.factory( false ); // $ExpectError - reduceRightAsync.factory( {}, 123 ); // $ExpectError - reduceRightAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1( 12, acc, done ); // $ExpectError - fcn1( true, acc, done ); // $ExpectError - fcn1( false, acc, done ); // $ExpectError - fcn1( {}, acc, done ); // $ExpectError - - fcn1( [ 3000, 2500, 1000 ], acc, 12 ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, true ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, false ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, '5' ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, {} ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, [] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1(); // $ExpectError - fcn1( [ 3000, 2500, 1000 ] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - reduceRightAsync.factory( { 'limit': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': true }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': false }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - reduceRightAsync.factory( { 'series': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': 12 }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - reduceRightAsync.factory(); // $ExpectError - reduceRightAsync.factory( {}, reducer, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index dd64345..0000000 --- a/examples/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var resolve = require( 'path' ).resolve; -var readFile = require( '@stdlib/fs-read-file' ); -var reduceRightAsync = require( './../lib' ); - -var files = [ - resolve( __dirname, '..', 'package.json' ), - resolve( __dirname, '..', 'README.md' ) -]; - -function done( error, acc ) { - if ( error ) { - throw error; - } - console.log( acc.count ); -} - -function read( acc, file, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( file, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( null, acc ); - } - acc.count += 1; - next( null, acc ); - } -} - -var acc = { - 'count': 0 -}; -reduceRightAsync( files, acc, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index b19e443..9dc0658 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { Collection } from '@stdlib/types/object'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..228c429 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import i from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";function d(i,t){return n(t)?(o(t,"thisArg")&&(i.thisArg=t.thisArg),o(t,"series")&&(i.series=t.series,!l(i.series))?new TypeError(s("0id30","series",i.series)):o(t,"limit")&&(i.limit=t.limit,!m(i.limit))?new TypeError(s("0id3b","limit",i.limit)):null):new TypeError(s("0id2h",t))}var f=()=>{};function h(i,t,e,s,r){var n,o,l,m,d,h;if(0===(m=i.length))return r(null,t);for(l=m0&&p();function p(){function r(i,e){if(!o){if(i)return o=!0,c(i);f("Accumulator: %s",JSON.stringify(e)),t=e,c()}}f("Collection element %d: %s.",d-=1,JSON.stringify(i[d])),3===s.length?s.call(e.thisArg,t,i[d],r):4===s.length?s.call(e.thisArg,t,i[d],d,r):s.call(e.thisArg,t,i[d],d,i,r)}function c(i){return i?(f("Encountered an error: %s",i.message),r(i)):(n+=1,d>0?p():n===m?r(null,t):void 0)}}function p(i,n){var o,l,m;if(o={},arguments.length>1){if(l=d(o,i))throw l;m=n}else m=i;if(!t(m))throw new TypeError(s("0id43",m));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=r),f;function f(i,r,n){if(!e(i))throw new TypeError(s("0idBO",i));if(!t(n))throw new TypeError(s("0id43",n));return h(i,r,o,m,(function(i,t){if(i)return n(i);n(null,t)}))}}function c(i,t,e,s,r){if(arguments.length<5)return p(e)(i,t,s);p(e,s)(i,t,r)}i(c,"factory",p);export{c as default,p as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..e8a1458 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/reduce_right.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean' ;\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\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( '0id2h', 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( '0id30', '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( '0id3b', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport logger from 'debug' ;\n\n\n// VARIABLES //\n\nvar debug = logger( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function' ;\nimport isCollection from '@stdlib/assert-is-collection' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport PINF from '@stdlib/constants-float64-pinf' ;\nimport validate from './validate.js' ;\nimport limit from './limit.js' ;\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0id43', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '0idBO', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0id43', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\n* @param {Collection} collection - input collection\n* @param {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file' ;\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right' ;\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport reduceRightAsync from './reduce_right.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( reduceRightAsync, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly"],"mappings":";;g2BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUR,EAAKK,SAGnDF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASR,EAAKS,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASP,QC7BrCU,SAkBJ,SAASF,EAAOG,EAAYC,EAAKb,EAAMc,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAAa,KAHbF,EAAMP,EAAWU,QAKhB,OAAOP,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMnB,EAAKS,MACTU,EAEAnB,EAAKS,MAGZE,EAAO,0BAA2BG,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdd,EAAO,kBAAmBiB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,KA3BDhB,EAAO,6BADPS,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM9B,EAAKI,QAASS,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM9B,EAAKI,QAASS,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM9B,EAAKI,QAASS,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,GAgCnE,SAASG,EAAMF,GACd,OAAKA,GACJd,EAAO,2BAA4Bc,EAAMM,SAClChB,EAAMU,KAEdT,GAAS,EAEJI,EAAM,EACHG,IAEHP,IAAUG,EAEPJ,EAAM,KAAMF,QAFpB,ICnCF,SAASmB,EAAS/B,EAASa,GAC1B,IAAId,EACAiC,EACAC,EAGJ,GADAlC,EAAO,GACFmC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMlC,EAAUC,EAAMC,GAErB,MAAMgC,EAEPC,EAAIpB,OAEJoB,EAAIjC,EAEL,IAAMmC,EAAYF,GACjB,MAAM,IAAI3B,UAAWC,EAAQ,QAAS0B,IAUvC,YARqB,IAAhBlC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ4B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIL,UAAWC,EAAQ,QAASI,IAEvC,IAAMwB,EAAYrB,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,OAAON,EAAOG,EAAY2B,EAASvC,EAAMkC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,OCvEf,SAASyB,EAAkB1B,EAAY2B,EAAStC,EAASa,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAS/B,EAAT+B,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAS/B,EAASa,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,GClB/C0B,EAAAH,EAAA,UAAAN"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 6d67be2..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var validate = require( './validate.js' ); -var limit = require( './limit.js' ); - - -// MAIN // - -/** -* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} last argument must be a function -* @returns {Function} function which invokes the provided function once for each element in a collection -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error, data ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var opts = { -* 'series': false -* }; -* -* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: -* var reduceRightAsync = factory( opts, read ); -* -* // Create a collection over which to iterate: -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* // Define a callback which handles errors: -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* // Run `read` for each element in `files`: -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, done ); -*/ -function factory( options, fcn ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = fcn; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '0id43', f ) ); - } - if ( opts.series === void 0 && opts.limit === void 0 ) { - opts.series = true; - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return reduceRightAsync; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * @private - * @param {Collection} collection - input collection - * @param {*} initial - initial value - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be a collection - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function reduceRightAsync( collection, initial, done ) { - if ( !isCollection( collection ) ) { - throw new TypeError( format( '0idBO', collection ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '0id43', done ) ); - } - return limit( collection, initial, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {*} [acc] - accumulated value - * @returns {void} - */ - function clbk( error, acc ) { - if ( error ) { - return done( error ); - } - done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 84aeb69..0000000 --- a/lib/index.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* @module @stdlib/utils-async-reduce-right -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' ); -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var reduceRightAsync = require( './reduce_right.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( reduceRightAsync, 'factory', factory ); - - -// EXPORTS // - -module.exports = reduceRightAsync; diff --git a/lib/limit.js b/lib/limit.js deleted file mode 100644 index cdb60af..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); - - -// VARIABLES // - -var debug = logger( 'reduce-right-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each element in a collection, limiting the number of concurrently pending functions and iterating from right to left. -* -* @private -* @param {Collection} collection - input collection -* @param {*} acc - initial value -* @param {Options} opts - function options -* @param {*} [opts.thisArg] - execution context -* @param {PositiveInteger} [opts.limit] - maximum number of pending function invocations -* @param {Function} fcn - function to invoke -* @param {Callback} done - function to invoke upon completion or upon encountering an error -* @returns {void} -*/ -function limit( collection, acc, opts, fcn, done ) { - var count; - var flg; - var lim; - var len; - var idx; - var i; - - len = collection.length; - debug( 'Collection length: %d', len ); - - if ( len === 0 ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - count = 0; - idx = len; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all collection elements... - if ( idx > 0 ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next element in a collection. - * - * @private - */ - function next() { - idx -= 1; - debug( 'Collection element %d: %s.', idx, JSON.stringify( collection[ idx ] ) ); - if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], cb ); - } else if ( fcn.length === 4 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, cb ); - } else { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len - } - /** - * Callback invoked once a provided function finishes processing a collection element. - * - * @private - * @param {*} [error] - error - * @param {*} [result] - accumulation result - * @returns {void} - */ - function cb( error, result ) { - if ( flg ) { - // Prevent further processing of collection elements: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Accumulator: %s', JSON.stringify( result ) ); - acc = result; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next collection element. - * - * @private - * @param {*} [error] - error - * @returns {void} - */ - function clbk( error ) { - if ( error ) { - debug( 'Encountered an error: %s', error.message ); - return done( error ); - } - count += 1; - debug( 'Processed %d of %d collection elements.', count, len ); - if ( idx > 0 ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/reduce_right.js b/lib/reduce_right.js deleted file mode 100644 index 9f016bf..0000000 --- a/lib/reduce_right.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param {Collection} collection - input collection -* @param {*} initial - initial value -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} second-to-last argument must be a function -* @throws {TypeError} last argument must be a function -* @returns {void} -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -function reduceRightAsync( collection, initial, options, fcn, done ) { - if ( arguments.length < 5 ) { - return factory( options )( collection, initial, fcn ); - } - factory( options, fcn )( collection, initial, done ); -} - - -// EXPORTS // - -module.exports = reduceRightAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 6292663..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @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 -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'thisArg': {}, -* 'series': false, -* 'limit': 10 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '0id2h', options ) ); - } - if ( hasOwnProp( options, 'thisArg' ) ) { - opts.thisArg = options.thisArg; - } - if ( hasOwnProp( options, 'series' ) ) { - opts.series = options.series; - if ( !isBoolean( opts.series ) ) { - return new TypeError( format( '0id30', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '0id3b', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 005e6d8..55f16d9 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.8", "description": "Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,43 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-boolean": "^0.0.x", - "@stdlib/assert-is-collection": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/assert-is-positive-integer": "^0.0.x", - "@stdlib/constants-float64-pinf": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/constants-float64-eps": "^0.0.x", - "@stdlib/fs-read-file": "^0.0.x", - "@stdlib/utils-noop": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a510e32 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 8244931..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1095 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( {}, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, next ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - factory( opts, next ); - }; - } -}); - -tape( 'the function returns a function (no options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided a collection (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a collection (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (1 argument)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (2 arguments)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with five arguments', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn() { - var value; - var next; - var acc; - var k; - - acc = arguments[ 0 ]; - value = arguments[ 1 ]; - k = arguments[ 2 ]; - next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( k, i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the returned function supports processing collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements concurrently', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 100, 250, 300 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements sequentially (limit = 1)', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of collection elements which are processed at any one time', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 250, 300, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 250, 100, 300 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var reduceRightAsync; - var arr; - - reduceRightAsync = factory( fcn ); - arr = []; - - reduceRightAsync( arr, 0, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var reduceRightAsync; - var obj; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = []; - obj = {}; - reduceRightAsync( arr, obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - i = 0; - - reduceRightAsync( arr, {}, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, acc ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the returned function does not skip empty elements', function test( t ) { - var reduceRightAsync; - var expected; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index f273a40..0000000 --- a/test/test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof reduceRightAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.reduce_right.js b/test/test.reduce_right.js deleted file mode 100644 index dc3e5d5..0000000 --- a/test/test.reduce_right.js +++ /dev/null @@ -1,1035 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var reduceRightAsync = require( './../lib/reduce_right.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a collection', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (no options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, next, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, 0 ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - reduceRightAsync( [ 1, 2, 3 ], 0, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (1 argument)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (2 arguments)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with five arguments', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn() { - var next; - var acc; - var v; - - next = arguments[ 4 ]; - acc = arguments[ 0 ]; - v = arguments[ 1 ]; - - i -= 1; - j += 1; - - t.strictEqual( v, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, v ); - - function onTimeout() { - acc.sum += v; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'by default, the function processes collection elements sequentially', function test( t ) { - var values; - var count; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements concurrently', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 100, 250, 300 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': true - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially (limit = 1)', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var arr; - var ctx; - - arr = [ 3, 2, 1 ]; - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 3, 2, 1 ]; - opts = { - 'series': true - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 250, 100, 300 ]; - opts = { - 'limit': 2 - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var arr = []; - reduceRightAsync( arr, 0, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var arr = []; - var obj = {}; - - reduceRightAsync( arr, obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - arr = [ 3, 2, 1 ]; - i = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, value ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the function does not skip empty elements', function test( t ) { - var expected; - var arr; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, fcn, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 7660838..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,181 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `limit` option which is not a positive integer', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - -5, - 0, - 3.14, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'limit': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `series` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'series': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function accepts any value for the `thisArg` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'thisArg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err, null, 'returns null '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'thisArg': {}, - 'series': false, - 'limit': 10 - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From e9522763855fc9ba078be01d146016ae3f7a9e4b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 17 Sep 2022 19:33:14 +0000 Subject: [PATCH 020/147] Transform error messages --- lib/factory.js | 8 ++++---- lib/validate.js | 8 ++++---- package.json | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index a627d69..6d67be2 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -22,7 +22,7 @@ var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var PINF = require( '@stdlib/constants-float64-pinf' ); var validate = require( './validate.js' ); var limit = require( './limit.js' ); @@ -110,7 +110,7 @@ function factory( options, fcn ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '0id43', f ) ); } if ( opts.series === void 0 && opts.limit === void 0 ) { opts.series = true; @@ -135,10 +135,10 @@ function factory( options, fcn ) { */ function reduceRightAsync( collection, initial, done ) { if ( !isCollection( collection ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a collection. Value: `%s`.', collection ) ); + throw new TypeError( format( '0idBO', collection ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '0id43', done ) ); } return limit( collection, initial, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index 9ba927e..6292663 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,7 +54,7 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0id2h', options ) ); } if ( hasOwnProp( options, 'thisArg' ) ) { opts.thisArg = options.thisArg; @@ -62,13 +62,13 @@ function validate( opts, options ) { if ( hasOwnProp( options, 'series' ) ) { opts.series = options.series; if ( !isBoolean( opts.series ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'series', opts.series ) ); + return new TypeError( format( '0id30', 'series', opts.series ) ); } } if ( hasOwnProp( options, 'limit' ) ) { opts.limit = options.limit; if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'limit', opts.limit ) ); + return new TypeError( format( '0id3b', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index fb48f96..005e6d8 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-plain-object": "^0.0.x", "@stdlib/assert-is-positive-integer": "^0.0.x", "@stdlib/constants-float64-pinf": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x", "debug": "^2.6.9" From 1a6a7dab58e30263814024ed3c193a3a5ed147cf Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 17 Sep 2022 19:41:24 +0000 Subject: [PATCH 021/147] Remove files --- index.d.ts | 415 -------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 3109 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 9dc0658..0000000 --- a/index.d.ts +++ /dev/null @@ -1,415 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Collection } from '@stdlib/types/object'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * The maximum number of pending invocations at any one time. - */ - limit?: number; - - /** - * Boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection (default: true). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback function. -*/ -type Nullary = () => void; - -/** -* Callback function. -* -* @param error - encountered error or null -*/ -type Unary = ( error: Error | null ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Binary = ( error: Error | null, accumulator: any ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param next - a callback to be invoked after processing a collection `value` -*/ -type TernaryReducer = ( accumulator: any, value: any, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuaternaryReducer = ( accumulator: any, value: any, index: number, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuinaryReducer = ( accumulator: any, value: any, index: number, collection: Collection, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type Reducer = TernaryReducer | QuaternaryReducer | QuinaryReducer; - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result. -* -* @param collection - input collection -* @param initial - initial value -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( collection: Collection, initial: any, done: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Interface for `reduceRightAsync`. -*/ -interface ReduceRightAsync { - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, {}, read, done ); - */ - ( collection: Collection, initial: any, options: Options, reducer: Reducer, done: Callback ): void; // tslint-disable-line max-line-length - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, read, done ); - */ - ( collection: Collection, initial: any, reducer: Reducer, done: Callback ): void; // tslint-disable-line max-line-length - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @throws must provide valid options - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var opts = { - * 'series': false - * }; - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( opts, read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( options: Options, reducer: Reducer ): FactoryFunction; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param reducer - function to invoke for each element in a collection - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( reducer: Reducer ): FactoryFunction; -} - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param collection - input collection -* @param initial - initial value -* @param options - function options -* @param options.thisArg - execution context -* @param options.limit - maximum number of pending invocations at any one time -* @param 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 (default: true) -* @param reducer - function to invoke for each element in a collection -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( `@stdlib/fs/read-file` ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -declare var reduceRightAsync: ReduceRightAsync; - - -// EXPORTS // - -export = reduceRightAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 228c429..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import i from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";function d(i,t){return n(t)?(o(t,"thisArg")&&(i.thisArg=t.thisArg),o(t,"series")&&(i.series=t.series,!l(i.series))?new TypeError(s("0id30","series",i.series)):o(t,"limit")&&(i.limit=t.limit,!m(i.limit))?new TypeError(s("0id3b","limit",i.limit)):null):new TypeError(s("0id2h",t))}var f=()=>{};function h(i,t,e,s,r){var n,o,l,m,d,h;if(0===(m=i.length))return r(null,t);for(l=m0&&p();function p(){function r(i,e){if(!o){if(i)return o=!0,c(i);f("Accumulator: %s",JSON.stringify(e)),t=e,c()}}f("Collection element %d: %s.",d-=1,JSON.stringify(i[d])),3===s.length?s.call(e.thisArg,t,i[d],r):4===s.length?s.call(e.thisArg,t,i[d],d,r):s.call(e.thisArg,t,i[d],d,i,r)}function c(i){return i?(f("Encountered an error: %s",i.message),r(i)):(n+=1,d>0?p():n===m?r(null,t):void 0)}}function p(i,n){var o,l,m;if(o={},arguments.length>1){if(l=d(o,i))throw l;m=n}else m=i;if(!t(m))throw new TypeError(s("0id43",m));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=r),f;function f(i,r,n){if(!e(i))throw new TypeError(s("0idBO",i));if(!t(n))throw new TypeError(s("0id43",n));return h(i,r,o,m,(function(i,t){if(i)return n(i);n(null,t)}))}}function c(i,t,e,s,r){if(arguments.length<5)return p(e)(i,t,s);p(e,s)(i,t,r)}i(c,"factory",p);export{c as default,p as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index e8a1458..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/reduce_right.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean' ;\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\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( '0id2h', 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( '0id30', '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( '0id3b', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport logger from 'debug' ;\n\n\n// VARIABLES //\n\nvar debug = logger( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function' ;\nimport isCollection from '@stdlib/assert-is-collection' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport PINF from '@stdlib/constants-float64-pinf' ;\nimport validate from './validate.js' ;\nimport limit from './limit.js' ;\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0id43', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '0idBO', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0id43', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\n* @param {Collection} collection - input collection\n* @param {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file' ;\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right' ;\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport reduceRightAsync from './reduce_right.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( reduceRightAsync, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly"],"mappings":";;g2BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUR,EAAKK,SAGnDF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASR,EAAKS,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASP,QC7BrCU,SAkBJ,SAASF,EAAOG,EAAYC,EAAKb,EAAMc,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAAa,KAHbF,EAAMP,EAAWU,QAKhB,OAAOP,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMnB,EAAKS,MACTU,EAEAnB,EAAKS,MAGZE,EAAO,0BAA2BG,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdd,EAAO,kBAAmBiB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,KA3BDhB,EAAO,6BADPS,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM9B,EAAKI,QAASS,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM9B,EAAKI,QAASS,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM9B,EAAKI,QAASS,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,GAgCnE,SAASG,EAAMF,GACd,OAAKA,GACJd,EAAO,2BAA4Bc,EAAMM,SAClChB,EAAMU,KAEdT,GAAS,EAEJI,EAAM,EACHG,IAEHP,IAAUG,EAEPJ,EAAM,KAAMF,QAFpB,ICnCF,SAASmB,EAAS/B,EAASa,GAC1B,IAAId,EACAiC,EACAC,EAGJ,GADAlC,EAAO,GACFmC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMlC,EAAUC,EAAMC,GAErB,MAAMgC,EAEPC,EAAIpB,OAEJoB,EAAIjC,EAEL,IAAMmC,EAAYF,GACjB,MAAM,IAAI3B,UAAWC,EAAQ,QAAS0B,IAUvC,YARqB,IAAhBlC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ4B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIL,UAAWC,EAAQ,QAASI,IAEvC,IAAMwB,EAAYrB,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,OAAON,EAAOG,EAAY2B,EAASvC,EAAMkC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,OCvEf,SAASyB,EAAkB1B,EAAY2B,EAAStC,EAASa,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAS/B,EAAT+B,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAS/B,EAASa,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,GClB/C0B,EAAAH,EAAA,UAAAN"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index a510e32..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From be6413063742573ccfa0120f6b7ca7f43d4b75c9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 17 Sep 2022 19:42:07 +0000 Subject: [PATCH 022/147] Auto-generated commit --- .editorconfig | 181 -- .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 760 ------ .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 -- .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 -- .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 ---- README.md | 47 +- benchmark/benchmark.factory.js | 73 - benchmark/benchmark.js | 160 -- branches.md | 53 - docs/repl.txt | 224 -- docs/types/test.ts | 166 -- examples/index.js | 55 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 165 -- lib/index.js | 77 - lib/limit.js | 142 -- lib/main.js | 96 - lib/validate.js | 80 - package.json | 64 +- stats.html | 2689 +++++++++++++++++++++ test/test.factory.js | 1095 --------- test/test.js | 38 - test/test.main.js | 1035 -------- test/test.validate.js | 181 -- 43 files changed, 2720 insertions(+), 6630 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/limit.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1e08946..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 29bf533..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a7a7f51..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.9.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 663f5df..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 39b1613..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 7ca169c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 8 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "::set-output name=package_name::$name" - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "::set-output name=data::$data" - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v2 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v2 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 5094681..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,760 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "::set-output name=alias::${alias}" - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -447,7 +446,7 @@ reduceRightAsync( files, acc, read, done ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -515,11 +514,11 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right +[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right/tree/esm -[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce +[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/tree/esm diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 46d8b83..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var reduceRightAsync; - var arr; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - reduceRightAsync = factory( onItem ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - var acc; - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 6ad0714..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var reduceRightAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=false', function benchmark( b ) { - var opts; - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'series': false - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var arr; - var len; - var acc; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'limit': 3 - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 2aded98..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right" -click B href "https://github.com/stdlib-js/utils-async-reduce-right/tree/main" -click C href "https://github.com/stdlib-js/utils-async-reduce-right/tree/production" -click D href "https://github.com/stdlib-js/utils-async-reduce-right/tree/esm" -click E href "https://github.com/stdlib-js/utils-async-reduce-right/tree/deno" -click F href "https://github.com/stdlib-js/utils-async-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right -[production-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3f22669..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,224 +0,0 @@ - -{{alias}}( collection, initial, [options,] reducer, done ) - Applies a function against an accumulator and each element in a collection - and returns the accumulated result, iterating from right to left. - - When invoked, `reducer` is provided a maximum of five arguments: - - - `accumulator`: accumulated value - - `value`: collection value - - `index`: collection index - - `collection`: the input collection - - `next`: a callback to be invoked after processing a collection `value` - - The actual number of provided arguments depends on function length. If - `reducer` accepts three arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `next` - - If `reducer` accepts four arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `index` - - `next` - - For every other `reducer` signature, `reducer` is provided all five - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `accumulator`: accumulated value - - If a provided function calls the `next` callback with a truthy `error` - argument, the function suspends execution and immediately calls the `done` - callback for subsequent `error` handling. - - Execution is *not* guaranteed to be asynchronous. To guarantee asynchrony, - 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`). - - The function does not support dynamic collection resizing. - - If provided an empty collection, the function invokes the `done` callback - with the `initial` value as the second argument. - - The function does not skip `undefined` elements. - - When processing collection elements concurrently, *beware* of race - conditions when updating an accumulator. This is especially true when an - accumulator is a primitive (e.g., a number). In general, prefer object - accumulators. - - Parameters - ---------- - collection: Array|TypedArray|Object - Input collection over which to iterate. If provided an object, the - object must be array-like (excluding strings and functions). - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - reducer: Function - The function to invoke for each element in a collection. - - done: Function - A callback invoked either upon processing all collection elements or - upon encountering an error. - - Examples - -------- - // Basic usage: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, fcn, done ) - 3000 - 2500 - 1000 - 6500 - - // Limit number of concurrent invocations: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'limit': 2 }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 2500 - 3000 - 1000 - 6500 - - // Process concurrently: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'series': false }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 1000 - 2500 - 3000 - 6500 - - -{{alias}}.factory( [options,] fcn ) - Returns a function which applies a function against an accumulator and each - element in a collection and returns the accumulated result, iterating from - right to left. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - fcn: Function - The function to invoke for each element in a collection. - - Returns - ------- - out: Function - A function which invokes a function for each element in a collection. - - Examples - -------- - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > var opts = { 'series': false }; - > var f = {{alias}}.factory( opts, fcn ); - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > f( arr, acc, done ) - 1000 - 2500 - 3000 - 6500 - > acc = { 'sum': 0 }; - > arr = [ 1000, 1500, 2000 ]; - > f( arr, acc, done ) - 1000 - 1500 - 2000 - 4500 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 143a132..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,166 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unsafe-any */ - -import reduceRightAsync = require( './index' ); - -const reducer = ( acc: any, value: number, index: number, next: Function ) => { - acc.sum += value; - if ( index === void 0 ) { - throw new Error( '`index` is missing.' ); - } - next( null, acc ); -}; - -const done = ( error: Error | null, acc: any ) => { - if ( error ) { - throw error; - } - if ( acc === void 0 ) { - throw new Error( '`acc` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( 2, acc, reducer, done ); // $ExpectError - reduceRightAsync( false, acc, reducer, done ); // $ExpectError - reduceRightAsync( true, acc, reducer, done ); // $ExpectError - reduceRightAsync( {}, acc, reducer, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a predicate argument which is not a predicate function... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 2, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, false, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, true, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 'abc', done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, [], done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a done callback argument which is not a function having a supported signature... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 2 ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, false ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, true ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 'abc' ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, {} ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, [] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const acc = { 'sum': 0 }; - reduceRightAsync(); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, reducer, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - reduceRightAsync.factory( reducer ); // $ExpectType FactoryFunction - reduceRightAsync.factory( { 'series': true }, reducer ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - reduceRightAsync.factory( [], reducer ); // $ExpectError - reduceRightAsync.factory( 123, reducer ); // $ExpectError - reduceRightAsync.factory( 'abc', reducer ); // $ExpectError - reduceRightAsync.factory( false, reducer ); // $ExpectError - reduceRightAsync.factory( true, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not a predicate function... -{ - reduceRightAsync.factory( {} ); // $ExpectError - reduceRightAsync.factory( true ); // $ExpectError - reduceRightAsync.factory( false ); // $ExpectError - reduceRightAsync.factory( {}, 123 ); // $ExpectError - reduceRightAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1( 12, acc, done ); // $ExpectError - fcn1( true, acc, done ); // $ExpectError - fcn1( false, acc, done ); // $ExpectError - fcn1( {}, acc, done ); // $ExpectError - - fcn1( [ 3000, 2500, 1000 ], acc, 12 ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, true ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, false ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, '5' ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, {} ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, [] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1(); // $ExpectError - fcn1( [ 3000, 2500, 1000 ] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - reduceRightAsync.factory( { 'limit': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': true }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': false }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - reduceRightAsync.factory( { 'series': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': 12 }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - reduceRightAsync.factory(); // $ExpectError - reduceRightAsync.factory( {}, reducer, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index dd64345..0000000 --- a/examples/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var resolve = require( 'path' ).resolve; -var readFile = require( '@stdlib/fs-read-file' ); -var reduceRightAsync = require( './../lib' ); - -var files = [ - resolve( __dirname, '..', 'package.json' ), - resolve( __dirname, '..', 'README.md' ) -]; - -function done( error, acc ) { - if ( error ) { - throw error; - } - console.log( acc.count ); -} - -function read( acc, file, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( file, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( null, acc ); - } - acc.count += 1; - next( null, acc ); - } -} - -var acc = { - 'count': 0 -}; -reduceRightAsync( files, acc, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index b19e443..9dc0658 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { Collection } from '@stdlib/types/object'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..228c429 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import i from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";function d(i,t){return n(t)?(o(t,"thisArg")&&(i.thisArg=t.thisArg),o(t,"series")&&(i.series=t.series,!l(i.series))?new TypeError(s("0id30","series",i.series)):o(t,"limit")&&(i.limit=t.limit,!m(i.limit))?new TypeError(s("0id3b","limit",i.limit)):null):new TypeError(s("0id2h",t))}var f=()=>{};function h(i,t,e,s,r){var n,o,l,m,d,h;if(0===(m=i.length))return r(null,t);for(l=m0&&p();function p(){function r(i,e){if(!o){if(i)return o=!0,c(i);f("Accumulator: %s",JSON.stringify(e)),t=e,c()}}f("Collection element %d: %s.",d-=1,JSON.stringify(i[d])),3===s.length?s.call(e.thisArg,t,i[d],r):4===s.length?s.call(e.thisArg,t,i[d],d,r):s.call(e.thisArg,t,i[d],d,i,r)}function c(i){return i?(f("Encountered an error: %s",i.message),r(i)):(n+=1,d>0?p():n===m?r(null,t):void 0)}}function p(i,n){var o,l,m;if(o={},arguments.length>1){if(l=d(o,i))throw l;m=n}else m=i;if(!t(m))throw new TypeError(s("0id43",m));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=r),f;function f(i,r,n){if(!e(i))throw new TypeError(s("0idBO",i));if(!t(n))throw new TypeError(s("0id43",n));return h(i,r,o,m,(function(i,t){if(i)return n(i);n(null,t)}))}}function c(i,t,e,s,r){if(arguments.length<5)return p(e)(i,t,s);p(e,s)(i,t,r)}i(c,"factory",p);export{c as default,p as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..32b6373 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean' ;\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\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( '0id2h', 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( '0id30', '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( '0id3b', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport logger from 'debug' ;\n\n\n// VARIABLES //\n\nvar debug = logger( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function' ;\nimport isCollection from '@stdlib/assert-is-collection' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport PINF from '@stdlib/constants-float64-pinf' ;\nimport validate from './validate.js' ;\nimport limit from './limit.js' ;\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0id43', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '0idBO', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0id43', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\n* @param {Collection} collection - input collection\n* @param {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file' ;\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right' ;\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport main from './main.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly","main"],"mappings":";;g2BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUR,EAAKK,SAGnDF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASR,EAAKS,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASP,QC7BrCU,SAkBJ,SAASF,EAAOG,EAAYC,EAAKb,EAAMc,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAAa,KAHbF,EAAMP,EAAWU,QAKhB,OAAOP,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMnB,EAAKS,MACTU,EAEAnB,EAAKS,MAGZE,EAAO,0BAA2BG,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdd,EAAO,kBAAmBiB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,KA3BDhB,EAAO,6BADPS,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM9B,EAAKI,QAASS,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM9B,EAAKI,QAASS,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM9B,EAAKI,QAASS,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,GAgCnE,SAASG,EAAMF,GACd,OAAKA,GACJd,EAAO,2BAA4Bc,EAAMM,SAClChB,EAAMU,KAEdT,GAAS,EAEJI,EAAM,EACHG,IAEHP,IAAUG,EAEPJ,EAAM,KAAMF,QAFpB,ICnCF,SAASmB,EAAS/B,EAASa,GAC1B,IAAId,EACAiC,EACAC,EAGJ,GADAlC,EAAO,GACFmC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMlC,EAAUC,EAAMC,GAErB,MAAMgC,EAEPC,EAAIpB,OAEJoB,EAAIjC,EAEL,IAAMmC,EAAYF,GACjB,MAAM,IAAI3B,UAAWC,EAAQ,QAAS0B,IAUvC,YARqB,IAAhBlC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ4B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIL,UAAWC,EAAQ,QAASI,IAEvC,IAAMwB,EAAYrB,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,OAAON,EAAOG,EAAY2B,EAASvC,EAAMkC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,OCvEf,SAASyB,EAAkB1B,EAAY2B,EAAStC,EAASa,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAS/B,EAAT+B,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAS/B,EAASa,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,GClB/C0B,EAAAC,EAAA,UAAAV"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 6d67be2..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var validate = require( './validate.js' ); -var limit = require( './limit.js' ); - - -// MAIN // - -/** -* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} last argument must be a function -* @returns {Function} function which invokes the provided function once for each element in a collection -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error, data ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var opts = { -* 'series': false -* }; -* -* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: -* var reduceRightAsync = factory( opts, read ); -* -* // Create a collection over which to iterate: -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* // Define a callback which handles errors: -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* // Run `read` for each element in `files`: -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, done ); -*/ -function factory( options, fcn ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = fcn; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '0id43', f ) ); - } - if ( opts.series === void 0 && opts.limit === void 0 ) { - opts.series = true; - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return reduceRightAsync; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * @private - * @param {Collection} collection - input collection - * @param {*} initial - initial value - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be a collection - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function reduceRightAsync( collection, initial, done ) { - if ( !isCollection( collection ) ) { - throw new TypeError( format( '0idBO', collection ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '0id43', done ) ); - } - return limit( collection, initial, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {*} [acc] - accumulated value - * @returns {void} - */ - function clbk( error, acc ) { - if ( error ) { - return done( error ); - } - done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ae657ff..0000000 --- a/lib/index.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* @module @stdlib/utils-async-reduce-right -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' ); -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/limit.js b/lib/limit.js deleted file mode 100644 index cdb60af..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); - - -// VARIABLES // - -var debug = logger( 'reduce-right-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each element in a collection, limiting the number of concurrently pending functions and iterating from right to left. -* -* @private -* @param {Collection} collection - input collection -* @param {*} acc - initial value -* @param {Options} opts - function options -* @param {*} [opts.thisArg] - execution context -* @param {PositiveInteger} [opts.limit] - maximum number of pending function invocations -* @param {Function} fcn - function to invoke -* @param {Callback} done - function to invoke upon completion or upon encountering an error -* @returns {void} -*/ -function limit( collection, acc, opts, fcn, done ) { - var count; - var flg; - var lim; - var len; - var idx; - var i; - - len = collection.length; - debug( 'Collection length: %d', len ); - - if ( len === 0 ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - count = 0; - idx = len; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all collection elements... - if ( idx > 0 ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next element in a collection. - * - * @private - */ - function next() { - idx -= 1; - debug( 'Collection element %d: %s.', idx, JSON.stringify( collection[ idx ] ) ); - if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], cb ); - } else if ( fcn.length === 4 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, cb ); - } else { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len - } - /** - * Callback invoked once a provided function finishes processing a collection element. - * - * @private - * @param {*} [error] - error - * @param {*} [result] - accumulation result - * @returns {void} - */ - function cb( error, result ) { - if ( flg ) { - // Prevent further processing of collection elements: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Accumulator: %s', JSON.stringify( result ) ); - acc = result; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next collection element. - * - * @private - * @param {*} [error] - error - * @returns {void} - */ - function clbk( error ) { - if ( error ) { - debug( 'Encountered an error: %s', error.message ); - return done( error ); - } - count += 1; - debug( 'Processed %d of %d collection elements.', count, len ); - if ( idx > 0 ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 9f016bf..0000000 --- a/lib/main.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param {Collection} collection - input collection -* @param {*} initial - initial value -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} second-to-last argument must be a function -* @throws {TypeError} last argument must be a function -* @returns {void} -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -function reduceRightAsync( collection, initial, options, fcn, done ) { - if ( arguments.length < 5 ) { - return factory( options )( collection, initial, fcn ); - } - factory( options, fcn )( collection, initial, done ); -} - - -// EXPORTS // - -module.exports = reduceRightAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 6292663..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @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 -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'thisArg': {}, -* 'series': false, -* 'limit': 10 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '0id2h', options ) ); - } - if ( hasOwnProp( options, 'thisArg' ) ) { - opts.thisArg = options.thisArg; - } - if ( hasOwnProp( options, 'series' ) ) { - opts.series = options.series; - if ( !isBoolean( opts.series ) ) { - return new TypeError( format( '0id30', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '0id3b', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 005e6d8..55f16d9 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.8", "description": "Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,43 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-boolean": "^0.0.x", - "@stdlib/assert-is-collection": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/assert-is-positive-integer": "^0.0.x", - "@stdlib/constants-float64-pinf": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/constants-float64-eps": "^0.0.x", - "@stdlib/fs-read-file": "^0.0.x", - "@stdlib/utils-noop": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..fe1faa0 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 8244931..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1095 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( {}, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, next ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - factory( opts, next ); - }; - } -}); - -tape( 'the function returns a function (no options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided a collection (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a collection (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (1 argument)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (2 arguments)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with five arguments', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn() { - var value; - var next; - var acc; - var k; - - acc = arguments[ 0 ]; - value = arguments[ 1 ]; - k = arguments[ 2 ]; - next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( k, i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the returned function supports processing collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements concurrently', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 100, 250, 300 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements sequentially (limit = 1)', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of collection elements which are processed at any one time', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 250, 300, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 250, 100, 300 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var reduceRightAsync; - var arr; - - reduceRightAsync = factory( fcn ); - arr = []; - - reduceRightAsync( arr, 0, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var reduceRightAsync; - var obj; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = []; - obj = {}; - reduceRightAsync( arr, obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - i = 0; - - reduceRightAsync( arr, {}, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, acc ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the returned function does not skip empty elements', function test( t ) { - var reduceRightAsync; - var expected; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index f273a40..0000000 --- a/test/test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof reduceRightAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 1893240..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1035 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a collection', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (no options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, next, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, 0 ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - reduceRightAsync( [ 1, 2, 3 ], 0, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (1 argument)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (2 arguments)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with five arguments', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn() { - var next; - var acc; - var v; - - next = arguments[ 4 ]; - acc = arguments[ 0 ]; - v = arguments[ 1 ]; - - i -= 1; - j += 1; - - t.strictEqual( v, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, v ); - - function onTimeout() { - acc.sum += v; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'by default, the function processes collection elements sequentially', function test( t ) { - var values; - var count; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements concurrently', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 100, 250, 300 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': true - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially (limit = 1)', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var arr; - var ctx; - - arr = [ 3, 2, 1 ]; - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 3, 2, 1 ]; - opts = { - 'series': true - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 250, 100, 300 ]; - opts = { - 'limit': 2 - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var arr = []; - reduceRightAsync( arr, 0, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var arr = []; - var obj = {}; - - reduceRightAsync( arr, obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - arr = [ 3, 2, 1 ]; - i = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, value ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the function does not skip empty elements', function test( t ) { - var expected; - var arr; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, fcn, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 7660838..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,181 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `limit` option which is not a positive integer', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - -5, - 0, - 3.14, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'limit': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `series` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'series': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function accepts any value for the `thisArg` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'thisArg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err, null, 'returns null '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'thisArg': {}, - 'series': false, - 'limit': 10 - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From 1e820e42c009be0826d022990c885d5b557ba526 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 04:44:03 +0000 Subject: [PATCH 023/147] Transform error messages --- lib/factory.js | 8 ++++---- lib/validate.js | 8 ++++---- package.json | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index a627d69..6d67be2 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -22,7 +22,7 @@ var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var PINF = require( '@stdlib/constants-float64-pinf' ); var validate = require( './validate.js' ); var limit = require( './limit.js' ); @@ -110,7 +110,7 @@ function factory( options, fcn ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '0id43', f ) ); } if ( opts.series === void 0 && opts.limit === void 0 ) { opts.series = true; @@ -135,10 +135,10 @@ function factory( options, fcn ) { */ function reduceRightAsync( collection, initial, done ) { if ( !isCollection( collection ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a collection. Value: `%s`.', collection ) ); + throw new TypeError( format( '0idBO', collection ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '0id43', done ) ); } return limit( collection, initial, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index 9ba927e..6292663 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,7 +54,7 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0id2h', options ) ); } if ( hasOwnProp( options, 'thisArg' ) ) { opts.thisArg = options.thisArg; @@ -62,13 +62,13 @@ function validate( opts, options ) { if ( hasOwnProp( options, 'series' ) ) { opts.series = options.series; if ( !isBoolean( opts.series ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'series', opts.series ) ); + return new TypeError( format( '0id30', 'series', opts.series ) ); } } if ( hasOwnProp( options, 'limit' ) ) { opts.limit = options.limit; if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'limit', opts.limit ) ); + return new TypeError( format( '0id3b', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index fb48f96..005e6d8 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-plain-object": "^0.0.x", "@stdlib/assert-is-positive-integer": "^0.0.x", "@stdlib/constants-float64-pinf": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x", "debug": "^2.6.9" From ef2fc2417d2cb4997bc2c411708f85b43a81ba05 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 19:36:48 +0000 Subject: [PATCH 024/147] Remove files --- index.d.ts | 415 -------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 3109 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 9dc0658..0000000 --- a/index.d.ts +++ /dev/null @@ -1,415 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Collection } from '@stdlib/types/object'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * The maximum number of pending invocations at any one time. - */ - limit?: number; - - /** - * Boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection (default: true). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback function. -*/ -type Nullary = () => void; - -/** -* Callback function. -* -* @param error - encountered error or null -*/ -type Unary = ( error: Error | null ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Binary = ( error: Error | null, accumulator: any ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param next - a callback to be invoked after processing a collection `value` -*/ -type TernaryReducer = ( accumulator: any, value: any, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuaternaryReducer = ( accumulator: any, value: any, index: number, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuinaryReducer = ( accumulator: any, value: any, index: number, collection: Collection, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type Reducer = TernaryReducer | QuaternaryReducer | QuinaryReducer; - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result. -* -* @param collection - input collection -* @param initial - initial value -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( collection: Collection, initial: any, done: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Interface for `reduceRightAsync`. -*/ -interface ReduceRightAsync { - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, {}, read, done ); - */ - ( collection: Collection, initial: any, options: Options, reducer: Reducer, done: Callback ): void; // tslint-disable-line max-line-length - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, read, done ); - */ - ( collection: Collection, initial: any, reducer: Reducer, done: Callback ): void; // tslint-disable-line max-line-length - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @throws must provide valid options - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var opts = { - * 'series': false - * }; - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( opts, read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( options: Options, reducer: Reducer ): FactoryFunction; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param reducer - function to invoke for each element in a collection - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( reducer: Reducer ): FactoryFunction; -} - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param collection - input collection -* @param initial - initial value -* @param options - function options -* @param options.thisArg - execution context -* @param options.limit - maximum number of pending invocations at any one time -* @param 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 (default: true) -* @param reducer - function to invoke for each element in a collection -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( `@stdlib/fs/read-file` ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -declare var reduceRightAsync: ReduceRightAsync; - - -// EXPORTS // - -export = reduceRightAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 228c429..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import i from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";function d(i,t){return n(t)?(o(t,"thisArg")&&(i.thisArg=t.thisArg),o(t,"series")&&(i.series=t.series,!l(i.series))?new TypeError(s("0id30","series",i.series)):o(t,"limit")&&(i.limit=t.limit,!m(i.limit))?new TypeError(s("0id3b","limit",i.limit)):null):new TypeError(s("0id2h",t))}var f=()=>{};function h(i,t,e,s,r){var n,o,l,m,d,h;if(0===(m=i.length))return r(null,t);for(l=m0&&p();function p(){function r(i,e){if(!o){if(i)return o=!0,c(i);f("Accumulator: %s",JSON.stringify(e)),t=e,c()}}f("Collection element %d: %s.",d-=1,JSON.stringify(i[d])),3===s.length?s.call(e.thisArg,t,i[d],r):4===s.length?s.call(e.thisArg,t,i[d],d,r):s.call(e.thisArg,t,i[d],d,i,r)}function c(i){return i?(f("Encountered an error: %s",i.message),r(i)):(n+=1,d>0?p():n===m?r(null,t):void 0)}}function p(i,n){var o,l,m;if(o={},arguments.length>1){if(l=d(o,i))throw l;m=n}else m=i;if(!t(m))throw new TypeError(s("0id43",m));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=r),f;function f(i,r,n){if(!e(i))throw new TypeError(s("0idBO",i));if(!t(n))throw new TypeError(s("0id43",n));return h(i,r,o,m,(function(i,t){if(i)return n(i);n(null,t)}))}}function c(i,t,e,s,r){if(arguments.length<5)return p(e)(i,t,s);p(e,s)(i,t,r)}i(c,"factory",p);export{c as default,p as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 32b6373..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean' ;\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\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( '0id2h', 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( '0id30', '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( '0id3b', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport logger from 'debug' ;\n\n\n// VARIABLES //\n\nvar debug = logger( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function' ;\nimport isCollection from '@stdlib/assert-is-collection' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport PINF from '@stdlib/constants-float64-pinf' ;\nimport validate from './validate.js' ;\nimport limit from './limit.js' ;\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0id43', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '0idBO', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0id43', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\n* @param {Collection} collection - input collection\n* @param {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file' ;\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right' ;\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport main from './main.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly","main"],"mappings":";;g2BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUR,EAAKK,SAGnDF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASR,EAAKS,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASP,QC7BrCU,SAkBJ,SAASF,EAAOG,EAAYC,EAAKb,EAAMc,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAAa,KAHbF,EAAMP,EAAWU,QAKhB,OAAOP,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMnB,EAAKS,MACTU,EAEAnB,EAAKS,MAGZE,EAAO,0BAA2BG,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdd,EAAO,kBAAmBiB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,KA3BDhB,EAAO,6BADPS,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM9B,EAAKI,QAASS,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM9B,EAAKI,QAASS,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM9B,EAAKI,QAASS,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,GAgCnE,SAASG,EAAMF,GACd,OAAKA,GACJd,EAAO,2BAA4Bc,EAAMM,SAClChB,EAAMU,KAEdT,GAAS,EAEJI,EAAM,EACHG,IAEHP,IAAUG,EAEPJ,EAAM,KAAMF,QAFpB,ICnCF,SAASmB,EAAS/B,EAASa,GAC1B,IAAId,EACAiC,EACAC,EAGJ,GADAlC,EAAO,GACFmC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMlC,EAAUC,EAAMC,GAErB,MAAMgC,EAEPC,EAAIpB,OAEJoB,EAAIjC,EAEL,IAAMmC,EAAYF,GACjB,MAAM,IAAI3B,UAAWC,EAAQ,QAAS0B,IAUvC,YARqB,IAAhBlC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ4B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIL,UAAWC,EAAQ,QAASI,IAEvC,IAAMwB,EAAYrB,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,OAAON,EAAOG,EAAY2B,EAASvC,EAAMkC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,OCvEf,SAASyB,EAAkB1B,EAAY2B,EAAStC,EAASa,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAS/B,EAAT+B,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAS/B,EAASa,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,GClB/C0B,EAAAC,EAAA,UAAAV"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index fe1faa0..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 2c305625f8244a80b59e7438d7fb857e1806d1bb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 19:37:29 +0000 Subject: [PATCH 025/147] Auto-generated commit --- .editorconfig | 181 -- .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 760 ------ .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 -- .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 -- .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 ---- README.md | 47 +- benchmark/benchmark.factory.js | 73 - benchmark/benchmark.js | 160 -- branches.md | 53 - docs/repl.txt | 224 -- docs/types/test.ts | 166 -- examples/index.js | 55 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 165 -- lib/index.js | 77 - lib/limit.js | 142 -- lib/main.js | 96 - lib/validate.js | 80 - package.json | 64 +- stats.html | 2689 +++++++++++++++++++++ test/test.factory.js | 1095 --------- test/test.js | 38 - test/test.main.js | 1035 -------- test/test.validate.js | 181 -- 44 files changed, 2720 insertions(+), 6631 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/limit.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index cfdbeac..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-10-01T01:34:25.175Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1e08946..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 29bf533..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a7a7f51..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.9.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 663f5df..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 39b1613..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 7ca169c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 8 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "::set-output name=package_name::$name" - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "::set-output name=data::$data" - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v2 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v2 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 5094681..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,760 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "::set-output name=alias::${alias}" - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -447,7 +446,7 @@ reduceRightAsync( files, acc, read, done ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -515,11 +514,11 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right +[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right/tree/esm -[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce +[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/tree/esm diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 46d8b83..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var reduceRightAsync; - var arr; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - reduceRightAsync = factory( onItem ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - var acc; - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 6ad0714..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var reduceRightAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=false', function benchmark( b ) { - var opts; - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'series': false - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var arr; - var len; - var acc; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'limit': 3 - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 2aded98..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right" -click B href "https://github.com/stdlib-js/utils-async-reduce-right/tree/main" -click C href "https://github.com/stdlib-js/utils-async-reduce-right/tree/production" -click D href "https://github.com/stdlib-js/utils-async-reduce-right/tree/esm" -click E href "https://github.com/stdlib-js/utils-async-reduce-right/tree/deno" -click F href "https://github.com/stdlib-js/utils-async-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right -[production-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3f22669..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,224 +0,0 @@ - -{{alias}}( collection, initial, [options,] reducer, done ) - Applies a function against an accumulator and each element in a collection - and returns the accumulated result, iterating from right to left. - - When invoked, `reducer` is provided a maximum of five arguments: - - - `accumulator`: accumulated value - - `value`: collection value - - `index`: collection index - - `collection`: the input collection - - `next`: a callback to be invoked after processing a collection `value` - - The actual number of provided arguments depends on function length. If - `reducer` accepts three arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `next` - - If `reducer` accepts four arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `index` - - `next` - - For every other `reducer` signature, `reducer` is provided all five - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `accumulator`: accumulated value - - If a provided function calls the `next` callback with a truthy `error` - argument, the function suspends execution and immediately calls the `done` - callback for subsequent `error` handling. - - Execution is *not* guaranteed to be asynchronous. To guarantee asynchrony, - 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`). - - The function does not support dynamic collection resizing. - - If provided an empty collection, the function invokes the `done` callback - with the `initial` value as the second argument. - - The function does not skip `undefined` elements. - - When processing collection elements concurrently, *beware* of race - conditions when updating an accumulator. This is especially true when an - accumulator is a primitive (e.g., a number). In general, prefer object - accumulators. - - Parameters - ---------- - collection: Array|TypedArray|Object - Input collection over which to iterate. If provided an object, the - object must be array-like (excluding strings and functions). - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - reducer: Function - The function to invoke for each element in a collection. - - done: Function - A callback invoked either upon processing all collection elements or - upon encountering an error. - - Examples - -------- - // Basic usage: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, fcn, done ) - 3000 - 2500 - 1000 - 6500 - - // Limit number of concurrent invocations: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'limit': 2 }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 2500 - 3000 - 1000 - 6500 - - // Process concurrently: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'series': false }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 1000 - 2500 - 3000 - 6500 - - -{{alias}}.factory( [options,] fcn ) - Returns a function which applies a function against an accumulator and each - element in a collection and returns the accumulated result, iterating from - right to left. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - fcn: Function - The function to invoke for each element in a collection. - - Returns - ------- - out: Function - A function which invokes a function for each element in a collection. - - Examples - -------- - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > var opts = { 'series': false }; - > var f = {{alias}}.factory( opts, fcn ); - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > f( arr, acc, done ) - 1000 - 2500 - 3000 - 6500 - > acc = { 'sum': 0 }; - > arr = [ 1000, 1500, 2000 ]; - > f( arr, acc, done ) - 1000 - 1500 - 2000 - 4500 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 143a132..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,166 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unsafe-any */ - -import reduceRightAsync = require( './index' ); - -const reducer = ( acc: any, value: number, index: number, next: Function ) => { - acc.sum += value; - if ( index === void 0 ) { - throw new Error( '`index` is missing.' ); - } - next( null, acc ); -}; - -const done = ( error: Error | null, acc: any ) => { - if ( error ) { - throw error; - } - if ( acc === void 0 ) { - throw new Error( '`acc` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( 2, acc, reducer, done ); // $ExpectError - reduceRightAsync( false, acc, reducer, done ); // $ExpectError - reduceRightAsync( true, acc, reducer, done ); // $ExpectError - reduceRightAsync( {}, acc, reducer, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a predicate argument which is not a predicate function... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 2, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, false, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, true, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 'abc', done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, [], done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a done callback argument which is not a function having a supported signature... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 2 ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, false ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, true ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 'abc' ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, {} ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, [] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const acc = { 'sum': 0 }; - reduceRightAsync(); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, reducer, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - reduceRightAsync.factory( reducer ); // $ExpectType FactoryFunction - reduceRightAsync.factory( { 'series': true }, reducer ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - reduceRightAsync.factory( [], reducer ); // $ExpectError - reduceRightAsync.factory( 123, reducer ); // $ExpectError - reduceRightAsync.factory( 'abc', reducer ); // $ExpectError - reduceRightAsync.factory( false, reducer ); // $ExpectError - reduceRightAsync.factory( true, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not a predicate function... -{ - reduceRightAsync.factory( {} ); // $ExpectError - reduceRightAsync.factory( true ); // $ExpectError - reduceRightAsync.factory( false ); // $ExpectError - reduceRightAsync.factory( {}, 123 ); // $ExpectError - reduceRightAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1( 12, acc, done ); // $ExpectError - fcn1( true, acc, done ); // $ExpectError - fcn1( false, acc, done ); // $ExpectError - fcn1( {}, acc, done ); // $ExpectError - - fcn1( [ 3000, 2500, 1000 ], acc, 12 ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, true ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, false ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, '5' ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, {} ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, [] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1(); // $ExpectError - fcn1( [ 3000, 2500, 1000 ] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - reduceRightAsync.factory( { 'limit': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': true }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': false }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - reduceRightAsync.factory( { 'series': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': 12 }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - reduceRightAsync.factory(); // $ExpectError - reduceRightAsync.factory( {}, reducer, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index dd64345..0000000 --- a/examples/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var resolve = require( 'path' ).resolve; -var readFile = require( '@stdlib/fs-read-file' ); -var reduceRightAsync = require( './../lib' ); - -var files = [ - resolve( __dirname, '..', 'package.json' ), - resolve( __dirname, '..', 'README.md' ) -]; - -function done( error, acc ) { - if ( error ) { - throw error; - } - console.log( acc.count ); -} - -function read( acc, file, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( file, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( null, acc ); - } - acc.count += 1; - next( null, acc ); - } -} - -var acc = { - 'count': 0 -}; -reduceRightAsync( files, acc, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index b19e443..9dc0658 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { Collection } from '@stdlib/types/object'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..228c429 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import i from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";function d(i,t){return n(t)?(o(t,"thisArg")&&(i.thisArg=t.thisArg),o(t,"series")&&(i.series=t.series,!l(i.series))?new TypeError(s("0id30","series",i.series)):o(t,"limit")&&(i.limit=t.limit,!m(i.limit))?new TypeError(s("0id3b","limit",i.limit)):null):new TypeError(s("0id2h",t))}var f=()=>{};function h(i,t,e,s,r){var n,o,l,m,d,h;if(0===(m=i.length))return r(null,t);for(l=m0&&p();function p(){function r(i,e){if(!o){if(i)return o=!0,c(i);f("Accumulator: %s",JSON.stringify(e)),t=e,c()}}f("Collection element %d: %s.",d-=1,JSON.stringify(i[d])),3===s.length?s.call(e.thisArg,t,i[d],r):4===s.length?s.call(e.thisArg,t,i[d],d,r):s.call(e.thisArg,t,i[d],d,i,r)}function c(i){return i?(f("Encountered an error: %s",i.message),r(i)):(n+=1,d>0?p():n===m?r(null,t):void 0)}}function p(i,n){var o,l,m;if(o={},arguments.length>1){if(l=d(o,i))throw l;m=n}else m=i;if(!t(m))throw new TypeError(s("0id43",m));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=r),f;function f(i,r,n){if(!e(i))throw new TypeError(s("0idBO",i));if(!t(n))throw new TypeError(s("0id43",n));return h(i,r,o,m,(function(i,t){if(i)return n(i);n(null,t)}))}}function c(i,t,e,s,r){if(arguments.length<5)return p(e)(i,t,s);p(e,s)(i,t,r)}i(c,"factory",p);export{c as default,p as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..32b6373 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean' ;\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\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( '0id2h', 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( '0id30', '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( '0id3b', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport logger from 'debug' ;\n\n\n// VARIABLES //\n\nvar debug = logger( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function' ;\nimport isCollection from '@stdlib/assert-is-collection' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport PINF from '@stdlib/constants-float64-pinf' ;\nimport validate from './validate.js' ;\nimport limit from './limit.js' ;\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0id43', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '0idBO', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0id43', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\n* @param {Collection} collection - input collection\n* @param {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file' ;\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right' ;\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport main from './main.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly","main"],"mappings":";;g2BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUR,EAAKK,SAGnDF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASR,EAAKS,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASP,QC7BrCU,SAkBJ,SAASF,EAAOG,EAAYC,EAAKb,EAAMc,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAAa,KAHbF,EAAMP,EAAWU,QAKhB,OAAOP,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMnB,EAAKS,MACTU,EAEAnB,EAAKS,MAGZE,EAAO,0BAA2BG,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdd,EAAO,kBAAmBiB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,KA3BDhB,EAAO,6BADPS,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM9B,EAAKI,QAASS,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM9B,EAAKI,QAASS,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM9B,EAAKI,QAASS,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,GAgCnE,SAASG,EAAMF,GACd,OAAKA,GACJd,EAAO,2BAA4Bc,EAAMM,SAClChB,EAAMU,KAEdT,GAAS,EAEJI,EAAM,EACHG,IAEHP,IAAUG,EAEPJ,EAAM,KAAMF,QAFpB,ICnCF,SAASmB,EAAS/B,EAASa,GAC1B,IAAId,EACAiC,EACAC,EAGJ,GADAlC,EAAO,GACFmC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMlC,EAAUC,EAAMC,GAErB,MAAMgC,EAEPC,EAAIpB,OAEJoB,EAAIjC,EAEL,IAAMmC,EAAYF,GACjB,MAAM,IAAI3B,UAAWC,EAAQ,QAAS0B,IAUvC,YARqB,IAAhBlC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ4B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIL,UAAWC,EAAQ,QAASI,IAEvC,IAAMwB,EAAYrB,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,OAAON,EAAOG,EAAY2B,EAASvC,EAAMkC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,OCvEf,SAASyB,EAAkB1B,EAAY2B,EAAStC,EAASa,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAS/B,EAAT+B,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAS/B,EAASa,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,GClB/C0B,EAAAC,EAAA,UAAAV"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 6d67be2..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var validate = require( './validate.js' ); -var limit = require( './limit.js' ); - - -// MAIN // - -/** -* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} last argument must be a function -* @returns {Function} function which invokes the provided function once for each element in a collection -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error, data ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var opts = { -* 'series': false -* }; -* -* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: -* var reduceRightAsync = factory( opts, read ); -* -* // Create a collection over which to iterate: -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* // Define a callback which handles errors: -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* // Run `read` for each element in `files`: -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, done ); -*/ -function factory( options, fcn ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = fcn; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '0id43', f ) ); - } - if ( opts.series === void 0 && opts.limit === void 0 ) { - opts.series = true; - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return reduceRightAsync; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * @private - * @param {Collection} collection - input collection - * @param {*} initial - initial value - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be a collection - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function reduceRightAsync( collection, initial, done ) { - if ( !isCollection( collection ) ) { - throw new TypeError( format( '0idBO', collection ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '0id43', done ) ); - } - return limit( collection, initial, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {*} [acc] - accumulated value - * @returns {void} - */ - function clbk( error, acc ) { - if ( error ) { - return done( error ); - } - done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ae657ff..0000000 --- a/lib/index.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* @module @stdlib/utils-async-reduce-right -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' ); -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/limit.js b/lib/limit.js deleted file mode 100644 index cdb60af..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); - - -// VARIABLES // - -var debug = logger( 'reduce-right-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each element in a collection, limiting the number of concurrently pending functions and iterating from right to left. -* -* @private -* @param {Collection} collection - input collection -* @param {*} acc - initial value -* @param {Options} opts - function options -* @param {*} [opts.thisArg] - execution context -* @param {PositiveInteger} [opts.limit] - maximum number of pending function invocations -* @param {Function} fcn - function to invoke -* @param {Callback} done - function to invoke upon completion or upon encountering an error -* @returns {void} -*/ -function limit( collection, acc, opts, fcn, done ) { - var count; - var flg; - var lim; - var len; - var idx; - var i; - - len = collection.length; - debug( 'Collection length: %d', len ); - - if ( len === 0 ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - count = 0; - idx = len; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all collection elements... - if ( idx > 0 ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next element in a collection. - * - * @private - */ - function next() { - idx -= 1; - debug( 'Collection element %d: %s.', idx, JSON.stringify( collection[ idx ] ) ); - if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], cb ); - } else if ( fcn.length === 4 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, cb ); - } else { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len - } - /** - * Callback invoked once a provided function finishes processing a collection element. - * - * @private - * @param {*} [error] - error - * @param {*} [result] - accumulation result - * @returns {void} - */ - function cb( error, result ) { - if ( flg ) { - // Prevent further processing of collection elements: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Accumulator: %s', JSON.stringify( result ) ); - acc = result; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next collection element. - * - * @private - * @param {*} [error] - error - * @returns {void} - */ - function clbk( error ) { - if ( error ) { - debug( 'Encountered an error: %s', error.message ); - return done( error ); - } - count += 1; - debug( 'Processed %d of %d collection elements.', count, len ); - if ( idx > 0 ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 9f016bf..0000000 --- a/lib/main.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param {Collection} collection - input collection -* @param {*} initial - initial value -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} second-to-last argument must be a function -* @throws {TypeError} last argument must be a function -* @returns {void} -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -function reduceRightAsync( collection, initial, options, fcn, done ) { - if ( arguments.length < 5 ) { - return factory( options )( collection, initial, fcn ); - } - factory( options, fcn )( collection, initial, done ); -} - - -// EXPORTS // - -module.exports = reduceRightAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 6292663..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @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 -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'thisArg': {}, -* 'series': false, -* 'limit': 10 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '0id2h', options ) ); - } - if ( hasOwnProp( options, 'thisArg' ) ) { - opts.thisArg = options.thisArg; - } - if ( hasOwnProp( options, 'series' ) ) { - opts.series = options.series; - if ( !isBoolean( opts.series ) ) { - return new TypeError( format( '0id30', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '0id3b', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 005e6d8..55f16d9 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.8", "description": "Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,43 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-boolean": "^0.0.x", - "@stdlib/assert-is-collection": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/assert-is-positive-integer": "^0.0.x", - "@stdlib/constants-float64-pinf": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/constants-float64-eps": "^0.0.x", - "@stdlib/fs-read-file": "^0.0.x", - "@stdlib/utils-noop": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..883844f --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 8244931..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1095 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( {}, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, next ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - factory( opts, next ); - }; - } -}); - -tape( 'the function returns a function (no options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided a collection (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a collection (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (1 argument)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (2 arguments)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with five arguments', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn() { - var value; - var next; - var acc; - var k; - - acc = arguments[ 0 ]; - value = arguments[ 1 ]; - k = arguments[ 2 ]; - next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( k, i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the returned function supports processing collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements concurrently', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 100, 250, 300 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements sequentially (limit = 1)', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of collection elements which are processed at any one time', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 250, 300, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 250, 100, 300 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var reduceRightAsync; - var arr; - - reduceRightAsync = factory( fcn ); - arr = []; - - reduceRightAsync( arr, 0, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var reduceRightAsync; - var obj; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = []; - obj = {}; - reduceRightAsync( arr, obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - i = 0; - - reduceRightAsync( arr, {}, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, acc ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the returned function does not skip empty elements', function test( t ) { - var reduceRightAsync; - var expected; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index f273a40..0000000 --- a/test/test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof reduceRightAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 1893240..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1035 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a collection', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (no options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, next, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, 0 ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - reduceRightAsync( [ 1, 2, 3 ], 0, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (1 argument)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (2 arguments)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with five arguments', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn() { - var next; - var acc; - var v; - - next = arguments[ 4 ]; - acc = arguments[ 0 ]; - v = arguments[ 1 ]; - - i -= 1; - j += 1; - - t.strictEqual( v, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, v ); - - function onTimeout() { - acc.sum += v; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'by default, the function processes collection elements sequentially', function test( t ) { - var values; - var count; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements concurrently', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 100, 250, 300 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': true - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially (limit = 1)', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var arr; - var ctx; - - arr = [ 3, 2, 1 ]; - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 3, 2, 1 ]; - opts = { - 'series': true - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 250, 100, 300 ]; - opts = { - 'limit': 2 - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var arr = []; - reduceRightAsync( arr, 0, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var arr = []; - var obj = {}; - - reduceRightAsync( arr, obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - arr = [ 3, 2, 1 ]; - i = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, value ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the function does not skip empty elements', function test( t ) { - var expected; - var arr; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, fcn, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 7660838..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,181 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `limit` option which is not a positive integer', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - -5, - 0, - 3.14, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'limit': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `series` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'series': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function accepts any value for the `thisArg` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'thisArg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err, null, 'returns null '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'thisArg': {}, - 'series': false, - 'limit': 10 - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From 9856e7abd93c42102280a1a88e70954546709b2d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 04:21:03 +0000 Subject: [PATCH 026/147] Transform error messages --- lib/factory.js | 8 ++++---- lib/validate.js | 8 ++++---- package.json | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index a627d69..6d67be2 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -22,7 +22,7 @@ var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var PINF = require( '@stdlib/constants-float64-pinf' ); var validate = require( './validate.js' ); var limit = require( './limit.js' ); @@ -110,7 +110,7 @@ function factory( options, fcn ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '0id43', f ) ); } if ( opts.series === void 0 && opts.limit === void 0 ) { opts.series = true; @@ -135,10 +135,10 @@ function factory( options, fcn ) { */ function reduceRightAsync( collection, initial, done ) { if ( !isCollection( collection ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a collection. Value: `%s`.', collection ) ); + throw new TypeError( format( '0idBO', collection ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '0id43', done ) ); } return limit( collection, initial, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index 9ba927e..6292663 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,7 +54,7 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0id2h', options ) ); } if ( hasOwnProp( options, 'thisArg' ) ) { opts.thisArg = options.thisArg; @@ -62,13 +62,13 @@ function validate( opts, options ) { if ( hasOwnProp( options, 'series' ) ) { opts.series = options.series; if ( !isBoolean( opts.series ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'series', opts.series ) ); + return new TypeError( format( '0id30', 'series', opts.series ) ); } } if ( hasOwnProp( options, 'limit' ) ) { opts.limit = options.limit; if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'limit', opts.limit ) ); + return new TypeError( format( '0id3b', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index fb48f96..005e6d8 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-plain-object": "^0.0.x", "@stdlib/assert-is-positive-integer": "^0.0.x", "@stdlib/constants-float64-pinf": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x", "debug": "^2.6.9" From 87efffaa2562f9c76b22f633b13c62c3da5af218 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 18:55:48 +0000 Subject: [PATCH 027/147] Remove files --- index.d.ts | 415 -------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 3109 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 9dc0658..0000000 --- a/index.d.ts +++ /dev/null @@ -1,415 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Collection } from '@stdlib/types/object'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * The maximum number of pending invocations at any one time. - */ - limit?: number; - - /** - * Boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection (default: true). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback function. -*/ -type Nullary = () => void; - -/** -* Callback function. -* -* @param error - encountered error or null -*/ -type Unary = ( error: Error | null ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Binary = ( error: Error | null, accumulator: any ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param next - a callback to be invoked after processing a collection `value` -*/ -type TernaryReducer = ( accumulator: any, value: any, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuaternaryReducer = ( accumulator: any, value: any, index: number, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuinaryReducer = ( accumulator: any, value: any, index: number, collection: Collection, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type Reducer = TernaryReducer | QuaternaryReducer | QuinaryReducer; - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result. -* -* @param collection - input collection -* @param initial - initial value -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( collection: Collection, initial: any, done: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Interface for `reduceRightAsync`. -*/ -interface ReduceRightAsync { - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, {}, read, done ); - */ - ( collection: Collection, initial: any, options: Options, reducer: Reducer, done: Callback ): void; // tslint-disable-line max-line-length - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, read, done ); - */ - ( collection: Collection, initial: any, reducer: Reducer, done: Callback ): void; // tslint-disable-line max-line-length - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @throws must provide valid options - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var opts = { - * 'series': false - * }; - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( opts, read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( options: Options, reducer: Reducer ): FactoryFunction; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param reducer - function to invoke for each element in a collection - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( reducer: Reducer ): FactoryFunction; -} - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param collection - input collection -* @param initial - initial value -* @param options - function options -* @param options.thisArg - execution context -* @param options.limit - maximum number of pending invocations at any one time -* @param 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 (default: true) -* @param reducer - function to invoke for each element in a collection -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( `@stdlib/fs/read-file` ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -declare var reduceRightAsync: ReduceRightAsync; - - -// EXPORTS // - -export = reduceRightAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 228c429..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import i from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";function d(i,t){return n(t)?(o(t,"thisArg")&&(i.thisArg=t.thisArg),o(t,"series")&&(i.series=t.series,!l(i.series))?new TypeError(s("0id30","series",i.series)):o(t,"limit")&&(i.limit=t.limit,!m(i.limit))?new TypeError(s("0id3b","limit",i.limit)):null):new TypeError(s("0id2h",t))}var f=()=>{};function h(i,t,e,s,r){var n,o,l,m,d,h;if(0===(m=i.length))return r(null,t);for(l=m0&&p();function p(){function r(i,e){if(!o){if(i)return o=!0,c(i);f("Accumulator: %s",JSON.stringify(e)),t=e,c()}}f("Collection element %d: %s.",d-=1,JSON.stringify(i[d])),3===s.length?s.call(e.thisArg,t,i[d],r):4===s.length?s.call(e.thisArg,t,i[d],d,r):s.call(e.thisArg,t,i[d],d,i,r)}function c(i){return i?(f("Encountered an error: %s",i.message),r(i)):(n+=1,d>0?p():n===m?r(null,t):void 0)}}function p(i,n){var o,l,m;if(o={},arguments.length>1){if(l=d(o,i))throw l;m=n}else m=i;if(!t(m))throw new TypeError(s("0id43",m));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=r),f;function f(i,r,n){if(!e(i))throw new TypeError(s("0idBO",i));if(!t(n))throw new TypeError(s("0id43",n));return h(i,r,o,m,(function(i,t){if(i)return n(i);n(null,t)}))}}function c(i,t,e,s,r){if(arguments.length<5)return p(e)(i,t,s);p(e,s)(i,t,r)}i(c,"factory",p);export{c as default,p as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 32b6373..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean' ;\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\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( '0id2h', 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( '0id30', '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( '0id3b', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport logger from 'debug' ;\n\n\n// VARIABLES //\n\nvar debug = logger( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function' ;\nimport isCollection from '@stdlib/assert-is-collection' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport PINF from '@stdlib/constants-float64-pinf' ;\nimport validate from './validate.js' ;\nimport limit from './limit.js' ;\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0id43', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '0idBO', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0id43', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\n* @param {Collection} collection - input collection\n* @param {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file' ;\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right' ;\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport main from './main.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly","main"],"mappings":";;g2BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUR,EAAKK,SAGnDF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASR,EAAKS,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASP,QC7BrCU,SAkBJ,SAASF,EAAOG,EAAYC,EAAKb,EAAMc,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAAa,KAHbF,EAAMP,EAAWU,QAKhB,OAAOP,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMnB,EAAKS,MACTU,EAEAnB,EAAKS,MAGZE,EAAO,0BAA2BG,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdd,EAAO,kBAAmBiB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,KA3BDhB,EAAO,6BADPS,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM9B,EAAKI,QAASS,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM9B,EAAKI,QAASS,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM9B,EAAKI,QAASS,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,GAgCnE,SAASG,EAAMF,GACd,OAAKA,GACJd,EAAO,2BAA4Bc,EAAMM,SAClChB,EAAMU,KAEdT,GAAS,EAEJI,EAAM,EACHG,IAEHP,IAAUG,EAEPJ,EAAM,KAAMF,QAFpB,ICnCF,SAASmB,EAAS/B,EAASa,GAC1B,IAAId,EACAiC,EACAC,EAGJ,GADAlC,EAAO,GACFmC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMlC,EAAUC,EAAMC,GAErB,MAAMgC,EAEPC,EAAIpB,OAEJoB,EAAIjC,EAEL,IAAMmC,EAAYF,GACjB,MAAM,IAAI3B,UAAWC,EAAQ,QAAS0B,IAUvC,YARqB,IAAhBlC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ4B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIL,UAAWC,EAAQ,QAASI,IAEvC,IAAMwB,EAAYrB,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,OAAON,EAAOG,EAAY2B,EAASvC,EAAMkC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,OCvEf,SAASyB,EAAkB1B,EAAY2B,EAAStC,EAASa,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAS/B,EAAT+B,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAS/B,EAASa,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,GClB/C0B,EAAAC,EAAA,UAAAV"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 883844f..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From b15e8832d879fc90e840519a48fc73ffab47fce5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 18:56:29 +0000 Subject: [PATCH 028/147] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 760 ---- .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 - .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 47 +- benchmark/benchmark.factory.js | 73 - benchmark/benchmark.js | 160 - branches.md | 53 - docs/repl.txt | 224 -- docs/types/test.ts | 166 - examples/index.js | 55 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 165 - lib/index.js | 77 - lib/limit.js | 142 - lib/main.js | 96 - lib/validate.js | 80 - package.json | 64 +- stats.html | 4044 +++++++++++++++++++++ test/test.factory.js | 1095 ------ test/test.js | 38 - test/test.main.js | 1035 ------ test/test.validate.js | 181 - 44 files changed, 4075 insertions(+), 6631 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/limit.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 078ebd0..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-11-01T01:22:40.374Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1e08946..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 663f5df..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 45a5053..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '37 1 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9113bfe..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,760 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -447,7 +446,7 @@ reduceRightAsync( files, acc, read, done ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -515,11 +514,11 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right +[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right/tree/esm -[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce +[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/tree/esm diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 46d8b83..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var reduceRightAsync; - var arr; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - reduceRightAsync = factory( onItem ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - var acc; - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 6ad0714..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var reduceRightAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=false', function benchmark( b ) { - var opts; - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'series': false - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var arr; - var len; - var acc; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'limit': 3 - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 2aded98..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right" -click B href "https://github.com/stdlib-js/utils-async-reduce-right/tree/main" -click C href "https://github.com/stdlib-js/utils-async-reduce-right/tree/production" -click D href "https://github.com/stdlib-js/utils-async-reduce-right/tree/esm" -click E href "https://github.com/stdlib-js/utils-async-reduce-right/tree/deno" -click F href "https://github.com/stdlib-js/utils-async-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right -[production-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3f22669..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,224 +0,0 @@ - -{{alias}}( collection, initial, [options,] reducer, done ) - Applies a function against an accumulator and each element in a collection - and returns the accumulated result, iterating from right to left. - - When invoked, `reducer` is provided a maximum of five arguments: - - - `accumulator`: accumulated value - - `value`: collection value - - `index`: collection index - - `collection`: the input collection - - `next`: a callback to be invoked after processing a collection `value` - - The actual number of provided arguments depends on function length. If - `reducer` accepts three arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `next` - - If `reducer` accepts four arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `index` - - `next` - - For every other `reducer` signature, `reducer` is provided all five - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `accumulator`: accumulated value - - If a provided function calls the `next` callback with a truthy `error` - argument, the function suspends execution and immediately calls the `done` - callback for subsequent `error` handling. - - Execution is *not* guaranteed to be asynchronous. To guarantee asynchrony, - 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`). - - The function does not support dynamic collection resizing. - - If provided an empty collection, the function invokes the `done` callback - with the `initial` value as the second argument. - - The function does not skip `undefined` elements. - - When processing collection elements concurrently, *beware* of race - conditions when updating an accumulator. This is especially true when an - accumulator is a primitive (e.g., a number). In general, prefer object - accumulators. - - Parameters - ---------- - collection: Array|TypedArray|Object - Input collection over which to iterate. If provided an object, the - object must be array-like (excluding strings and functions). - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - reducer: Function - The function to invoke for each element in a collection. - - done: Function - A callback invoked either upon processing all collection elements or - upon encountering an error. - - Examples - -------- - // Basic usage: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, fcn, done ) - 3000 - 2500 - 1000 - 6500 - - // Limit number of concurrent invocations: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'limit': 2 }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 2500 - 3000 - 1000 - 6500 - - // Process concurrently: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'series': false }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 1000 - 2500 - 3000 - 6500 - - -{{alias}}.factory( [options,] fcn ) - Returns a function which applies a function against an accumulator and each - element in a collection and returns the accumulated result, iterating from - right to left. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - fcn: Function - The function to invoke for each element in a collection. - - Returns - ------- - out: Function - A function which invokes a function for each element in a collection. - - Examples - -------- - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > var opts = { 'series': false }; - > var f = {{alias}}.factory( opts, fcn ); - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > f( arr, acc, done ) - 1000 - 2500 - 3000 - 6500 - > acc = { 'sum': 0 }; - > arr = [ 1000, 1500, 2000 ]; - > f( arr, acc, done ) - 1000 - 1500 - 2000 - 4500 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 143a132..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,166 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unsafe-any */ - -import reduceRightAsync = require( './index' ); - -const reducer = ( acc: any, value: number, index: number, next: Function ) => { - acc.sum += value; - if ( index === void 0 ) { - throw new Error( '`index` is missing.' ); - } - next( null, acc ); -}; - -const done = ( error: Error | null, acc: any ) => { - if ( error ) { - throw error; - } - if ( acc === void 0 ) { - throw new Error( '`acc` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( 2, acc, reducer, done ); // $ExpectError - reduceRightAsync( false, acc, reducer, done ); // $ExpectError - reduceRightAsync( true, acc, reducer, done ); // $ExpectError - reduceRightAsync( {}, acc, reducer, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a predicate argument which is not a predicate function... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 2, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, false, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, true, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 'abc', done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, [], done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a done callback argument which is not a function having a supported signature... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 2 ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, false ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, true ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 'abc' ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, {} ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, [] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const acc = { 'sum': 0 }; - reduceRightAsync(); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, reducer, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - reduceRightAsync.factory( reducer ); // $ExpectType FactoryFunction - reduceRightAsync.factory( { 'series': true }, reducer ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - reduceRightAsync.factory( [], reducer ); // $ExpectError - reduceRightAsync.factory( 123, reducer ); // $ExpectError - reduceRightAsync.factory( 'abc', reducer ); // $ExpectError - reduceRightAsync.factory( false, reducer ); // $ExpectError - reduceRightAsync.factory( true, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not a predicate function... -{ - reduceRightAsync.factory( {} ); // $ExpectError - reduceRightAsync.factory( true ); // $ExpectError - reduceRightAsync.factory( false ); // $ExpectError - reduceRightAsync.factory( {}, 123 ); // $ExpectError - reduceRightAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1( 12, acc, done ); // $ExpectError - fcn1( true, acc, done ); // $ExpectError - fcn1( false, acc, done ); // $ExpectError - fcn1( {}, acc, done ); // $ExpectError - - fcn1( [ 3000, 2500, 1000 ], acc, 12 ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, true ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, false ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, '5' ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, {} ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, [] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1(); // $ExpectError - fcn1( [ 3000, 2500, 1000 ] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - reduceRightAsync.factory( { 'limit': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': true }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': false }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - reduceRightAsync.factory( { 'series': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': 12 }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - reduceRightAsync.factory(); // $ExpectError - reduceRightAsync.factory( {}, reducer, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index dd64345..0000000 --- a/examples/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var resolve = require( 'path' ).resolve; -var readFile = require( '@stdlib/fs-read-file' ); -var reduceRightAsync = require( './../lib' ); - -var files = [ - resolve( __dirname, '..', 'package.json' ), - resolve( __dirname, '..', 'README.md' ) -]; - -function done( error, acc ) { - if ( error ) { - throw error; - } - console.log( acc.count ); -} - -function read( acc, file, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( file, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( null, acc ); - } - acc.count += 1; - next( null, acc ); - } -} - -var acc = { - 'count': 0 -}; -reduceRightAsync( files, acc, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index b19e443..9dc0658 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { Collection } from '@stdlib/types/object'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..d5648fc --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import i from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.7-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";function d(i,t){return n(t)?(o(t,"thisArg")&&(i.thisArg=t.thisArg),o(t,"series")&&(i.series=t.series,!l(i.series))?new TypeError(s("0id30","series",i.series)):o(t,"limit")&&(i.limit=t.limit,!m(i.limit))?new TypeError(s("0id3b","limit",i.limit)):null):new TypeError(s("0id2h",t))}var f=()=>{};function h(i,t,e,s,r){var n,o,l,m,d,h;if(0===(m=i.length))return r(null,t);for(l=m0&&p();function p(){function r(i,e){if(!o){if(i)return o=!0,c(i);f("Accumulator: %s",JSON.stringify(e)),t=e,c()}}f("Collection element %d: %s.",d-=1,JSON.stringify(i[d])),3===s.length?s.call(e.thisArg,t,i[d],r):4===s.length?s.call(e.thisArg,t,i[d],d,r):s.call(e.thisArg,t,i[d],d,i,r)}function c(i){return i?(f("Encountered an error: %s",i.message),r(i)):(n+=1,d>0?p():n===m?r(null,t):void 0)}}function p(i,n){var o,l,m;if(o={},arguments.length>1){if(l=d(o,i))throw l;m=n}else m=i;if(!t(m))throw new TypeError(s("0id43",m));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=r),f;function f(i,r,n){if(!e(i))throw new TypeError(s("0idBO",i));if(!t(n))throw new TypeError(s("0id43",n));return h(i,r,o,m,(function(i,t){if(i)return n(i);n(null,t)}))}}function c(i,t,e,s,r){if(arguments.length<5)return p(e)(i,t,s);p(e,s)(i,t,r)}i(c,"factory",p);export{c as default,p as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..fdfce8c --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean' ;\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\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( '0id2h', 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( '0id30', '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( '0id3b', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport logger from 'debug' ;\n\n\n// VARIABLES //\n\nvar debug = logger( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function' ;\nimport isCollection from '@stdlib/assert-is-collection' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport PINF from '@stdlib/constants-float64-pinf' ;\nimport validate from './validate.js' ;\nimport limit from './limit.js' ;\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0id43', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '0idBO', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0id43', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\n* @param {Collection} collection - input collection\n* @param {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file' ;\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right' ;\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport main from './main.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly","main"],"mappings":";;u2BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUR,EAAKK,SAGnDF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASR,EAAKS,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASP,GAkBzC,KC/CIU,SAkBJ,SAASF,EAAOG,EAAYC,EAAKb,EAAMc,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAAa,KAHbF,EAAMP,EAAWU,QAKhB,OAAOP,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMnB,EAAKS,MACTU,EAEAnB,EAAKS,MAGZE,EAAO,0BAA2BG,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdd,EAAO,kBAAmBiB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,GAPC,CAQD,CA5BDhB,EAAO,6BADPS,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM9B,EAAKI,QAASS,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM9B,EAAKI,QAASS,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM9B,EAAKI,QAASS,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJd,EAAO,2BAA4Bc,EAAMM,SAClChB,EAAMU,KAEdT,GAAS,EAEJI,EAAM,EACHG,IAEHP,IAAUG,EAEPJ,EAAM,KAAMF,QAFpB,EAIA,CACF,CCxCA,SAASmB,EAAS/B,EAASa,GAC1B,IAAId,EACAiC,EACAC,EAGJ,GADAlC,EAAO,CAAA,EACFmC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMlC,EAAUC,EAAMC,GAErB,MAAMgC,EAEPC,EAAIpB,CACN,MACEoB,EAAIjC,EAEL,IAAMmC,EAAYF,GACjB,MAAM,IAAI3B,UAAWC,EAAQ,QAAS0B,IAUvC,YARqB,IAAhBlC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ4B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIL,UAAWC,EAAQ,QAASI,IAEvC,IAAMwB,EAAYrB,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,OAAON,EAAOG,EAAY2B,EAASvC,EAAMkC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,EACZ,GACD,CACF,CC1EA,SAASyB,EAAkB1B,EAAY2B,EAAStC,EAASa,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAS/B,EAAT+B,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAS/B,EAASa,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,EAC/C,CCnBA0B,EAAAC,EAAA,UAAAV"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 6d67be2..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var validate = require( './validate.js' ); -var limit = require( './limit.js' ); - - -// MAIN // - -/** -* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} last argument must be a function -* @returns {Function} function which invokes the provided function once for each element in a collection -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error, data ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var opts = { -* 'series': false -* }; -* -* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: -* var reduceRightAsync = factory( opts, read ); -* -* // Create a collection over which to iterate: -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* // Define a callback which handles errors: -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* // Run `read` for each element in `files`: -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, done ); -*/ -function factory( options, fcn ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = fcn; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '0id43', f ) ); - } - if ( opts.series === void 0 && opts.limit === void 0 ) { - opts.series = true; - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return reduceRightAsync; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * @private - * @param {Collection} collection - input collection - * @param {*} initial - initial value - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be a collection - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function reduceRightAsync( collection, initial, done ) { - if ( !isCollection( collection ) ) { - throw new TypeError( format( '0idBO', collection ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '0id43', done ) ); - } - return limit( collection, initial, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {*} [acc] - accumulated value - * @returns {void} - */ - function clbk( error, acc ) { - if ( error ) { - return done( error ); - } - done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ae657ff..0000000 --- a/lib/index.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* @module @stdlib/utils-async-reduce-right -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' ); -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/limit.js b/lib/limit.js deleted file mode 100644 index cdb60af..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); - - -// VARIABLES // - -var debug = logger( 'reduce-right-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each element in a collection, limiting the number of concurrently pending functions and iterating from right to left. -* -* @private -* @param {Collection} collection - input collection -* @param {*} acc - initial value -* @param {Options} opts - function options -* @param {*} [opts.thisArg] - execution context -* @param {PositiveInteger} [opts.limit] - maximum number of pending function invocations -* @param {Function} fcn - function to invoke -* @param {Callback} done - function to invoke upon completion or upon encountering an error -* @returns {void} -*/ -function limit( collection, acc, opts, fcn, done ) { - var count; - var flg; - var lim; - var len; - var idx; - var i; - - len = collection.length; - debug( 'Collection length: %d', len ); - - if ( len === 0 ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - count = 0; - idx = len; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all collection elements... - if ( idx > 0 ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next element in a collection. - * - * @private - */ - function next() { - idx -= 1; - debug( 'Collection element %d: %s.', idx, JSON.stringify( collection[ idx ] ) ); - if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], cb ); - } else if ( fcn.length === 4 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, cb ); - } else { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len - } - /** - * Callback invoked once a provided function finishes processing a collection element. - * - * @private - * @param {*} [error] - error - * @param {*} [result] - accumulation result - * @returns {void} - */ - function cb( error, result ) { - if ( flg ) { - // Prevent further processing of collection elements: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Accumulator: %s', JSON.stringify( result ) ); - acc = result; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next collection element. - * - * @private - * @param {*} [error] - error - * @returns {void} - */ - function clbk( error ) { - if ( error ) { - debug( 'Encountered an error: %s', error.message ); - return done( error ); - } - count += 1; - debug( 'Processed %d of %d collection elements.', count, len ); - if ( idx > 0 ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 9f016bf..0000000 --- a/lib/main.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param {Collection} collection - input collection -* @param {*} initial - initial value -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} second-to-last argument must be a function -* @throws {TypeError} last argument must be a function -* @returns {void} -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -function reduceRightAsync( collection, initial, options, fcn, done ) { - if ( arguments.length < 5 ) { - return factory( options )( collection, initial, fcn ); - } - factory( options, fcn )( collection, initial, done ); -} - - -// EXPORTS // - -module.exports = reduceRightAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 6292663..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @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 -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'thisArg': {}, -* 'series': false, -* 'limit': 10 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '0id2h', options ) ); - } - if ( hasOwnProp( options, 'thisArg' ) ) { - opts.thisArg = options.thisArg; - } - if ( hasOwnProp( options, 'series' ) ) { - opts.series = options.series; - if ( !isBoolean( opts.series ) ) { - return new TypeError( format( '0id30', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '0id3b', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 005e6d8..55f16d9 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.8", "description": "Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,43 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-boolean": "^0.0.x", - "@stdlib/assert-is-collection": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/assert-is-positive-integer": "^0.0.x", - "@stdlib/constants-float64-pinf": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/constants-float64-eps": "^0.0.x", - "@stdlib/fs-read-file": "^0.0.x", - "@stdlib/utils-noop": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..b524e83 --- /dev/null +++ b/stats.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 8244931..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1095 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( {}, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, next ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - factory( opts, next ); - }; - } -}); - -tape( 'the function returns a function (no options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided a collection (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a collection (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (1 argument)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (2 arguments)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with five arguments', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn() { - var value; - var next; - var acc; - var k; - - acc = arguments[ 0 ]; - value = arguments[ 1 ]; - k = arguments[ 2 ]; - next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( k, i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the returned function supports processing collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements concurrently', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 100, 250, 300 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements sequentially (limit = 1)', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of collection elements which are processed at any one time', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 250, 300, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 250, 100, 300 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var reduceRightAsync; - var arr; - - reduceRightAsync = factory( fcn ); - arr = []; - - reduceRightAsync( arr, 0, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var reduceRightAsync; - var obj; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = []; - obj = {}; - reduceRightAsync( arr, obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - i = 0; - - reduceRightAsync( arr, {}, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, acc ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the returned function does not skip empty elements', function test( t ) { - var reduceRightAsync; - var expected; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index f273a40..0000000 --- a/test/test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof reduceRightAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 1893240..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1035 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a collection', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (no options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, next, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, 0 ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - reduceRightAsync( [ 1, 2, 3 ], 0, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (1 argument)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (2 arguments)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with five arguments', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn() { - var next; - var acc; - var v; - - next = arguments[ 4 ]; - acc = arguments[ 0 ]; - v = arguments[ 1 ]; - - i -= 1; - j += 1; - - t.strictEqual( v, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, v ); - - function onTimeout() { - acc.sum += v; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'by default, the function processes collection elements sequentially', function test( t ) { - var values; - var count; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements concurrently', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 100, 250, 300 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': true - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially (limit = 1)', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var arr; - var ctx; - - arr = [ 3, 2, 1 ]; - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 3, 2, 1 ]; - opts = { - 'series': true - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 250, 100, 300 ]; - opts = { - 'limit': 2 - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var arr = []; - reduceRightAsync( arr, 0, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var arr = []; - var obj = {}; - - reduceRightAsync( arr, obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - arr = [ 3, 2, 1 ]; - i = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, value ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the function does not skip empty elements', function test( t ) { - var expected; - var arr; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, fcn, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 7660838..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,181 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `limit` option which is not a positive integer', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - -5, - 0, - 3.14, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'limit': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `series` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'series': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function accepts any value for the `thisArg` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'thisArg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err, null, 'returns null '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'thisArg': {}, - 'series': false, - 'limit': 10 - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From 1520a339fbbec7fb7edd2f7977b1c45cbef34d69 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 3 Nov 2022 21:57:42 +0000 Subject: [PATCH 029/147] Transform error messages --- lib/factory.js | 8 ++++---- lib/validate.js | 8 ++++---- package.json | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index a627d69..6d67be2 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -22,7 +22,7 @@ var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var PINF = require( '@stdlib/constants-float64-pinf' ); var validate = require( './validate.js' ); var limit = require( './limit.js' ); @@ -110,7 +110,7 @@ function factory( options, fcn ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '0id43', f ) ); } if ( opts.series === void 0 && opts.limit === void 0 ) { opts.series = true; @@ -135,10 +135,10 @@ function factory( options, fcn ) { */ function reduceRightAsync( collection, initial, done ) { if ( !isCollection( collection ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a collection. Value: `%s`.', collection ) ); + throw new TypeError( format( '0idBO', collection ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '0id43', done ) ); } return limit( collection, initial, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index 9ba927e..6292663 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,7 +54,7 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0id2h', options ) ); } if ( hasOwnProp( options, 'thisArg' ) ) { opts.thisArg = options.thisArg; @@ -62,13 +62,13 @@ function validate( opts, options ) { if ( hasOwnProp( options, 'series' ) ) { opts.series = options.series; if ( !isBoolean( opts.series ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'series', opts.series ) ); + return new TypeError( format( '0id30', 'series', opts.series ) ); } } if ( hasOwnProp( options, 'limit' ) ) { opts.limit = options.limit; if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'limit', opts.limit ) ); + return new TypeError( format( '0id3b', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index fb48f96..005e6d8 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-plain-object": "^0.0.x", "@stdlib/assert-is-positive-integer": "^0.0.x", "@stdlib/constants-float64-pinf": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x", "debug": "^2.6.9" From 9b44a268775f928e0d487e52110d370ca46eb173 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Nov 2022 07:42:12 +0000 Subject: [PATCH 030/147] Remove files --- index.d.ts | 415 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4464 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 9dc0658..0000000 --- a/index.d.ts +++ /dev/null @@ -1,415 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Collection } from '@stdlib/types/object'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * The maximum number of pending invocations at any one time. - */ - limit?: number; - - /** - * Boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection (default: true). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback function. -*/ -type Nullary = () => void; - -/** -* Callback function. -* -* @param error - encountered error or null -*/ -type Unary = ( error: Error | null ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Binary = ( error: Error | null, accumulator: any ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param next - a callback to be invoked after processing a collection `value` -*/ -type TernaryReducer = ( accumulator: any, value: any, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuaternaryReducer = ( accumulator: any, value: any, index: number, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuinaryReducer = ( accumulator: any, value: any, index: number, collection: Collection, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type Reducer = TernaryReducer | QuaternaryReducer | QuinaryReducer; - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result. -* -* @param collection - input collection -* @param initial - initial value -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( collection: Collection, initial: any, done: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Interface for `reduceRightAsync`. -*/ -interface ReduceRightAsync { - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, {}, read, done ); - */ - ( collection: Collection, initial: any, options: Options, reducer: Reducer, done: Callback ): void; // tslint-disable-line max-line-length - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, read, done ); - */ - ( collection: Collection, initial: any, reducer: Reducer, done: Callback ): void; // tslint-disable-line max-line-length - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @throws must provide valid options - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var opts = { - * 'series': false - * }; - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( opts, read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( options: Options, reducer: Reducer ): FactoryFunction; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param reducer - function to invoke for each element in a collection - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( reducer: Reducer ): FactoryFunction; -} - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param collection - input collection -* @param initial - initial value -* @param options - function options -* @param options.thisArg - execution context -* @param options.limit - maximum number of pending invocations at any one time -* @param 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 (default: true) -* @param reducer - function to invoke for each element in a collection -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( `@stdlib/fs/read-file` ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -declare var reduceRightAsync: ReduceRightAsync; - - -// EXPORTS // - -export = reduceRightAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index d5648fc..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import i from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.7-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";function d(i,t){return n(t)?(o(t,"thisArg")&&(i.thisArg=t.thisArg),o(t,"series")&&(i.series=t.series,!l(i.series))?new TypeError(s("0id30","series",i.series)):o(t,"limit")&&(i.limit=t.limit,!m(i.limit))?new TypeError(s("0id3b","limit",i.limit)):null):new TypeError(s("0id2h",t))}var f=()=>{};function h(i,t,e,s,r){var n,o,l,m,d,h;if(0===(m=i.length))return r(null,t);for(l=m0&&p();function p(){function r(i,e){if(!o){if(i)return o=!0,c(i);f("Accumulator: %s",JSON.stringify(e)),t=e,c()}}f("Collection element %d: %s.",d-=1,JSON.stringify(i[d])),3===s.length?s.call(e.thisArg,t,i[d],r):4===s.length?s.call(e.thisArg,t,i[d],d,r):s.call(e.thisArg,t,i[d],d,i,r)}function c(i){return i?(f("Encountered an error: %s",i.message),r(i)):(n+=1,d>0?p():n===m?r(null,t):void 0)}}function p(i,n){var o,l,m;if(o={},arguments.length>1){if(l=d(o,i))throw l;m=n}else m=i;if(!t(m))throw new TypeError(s("0id43",m));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=r),f;function f(i,r,n){if(!e(i))throw new TypeError(s("0idBO",i));if(!t(n))throw new TypeError(s("0id43",n));return h(i,r,o,m,(function(i,t){if(i)return n(i);n(null,t)}))}}function c(i,t,e,s,r){if(arguments.length<5)return p(e)(i,t,s);p(e,s)(i,t,r)}i(c,"factory",p);export{c as default,p as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index fdfce8c..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean' ;\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\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( '0id2h', 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( '0id30', '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( '0id3b', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport logger from 'debug' ;\n\n\n// VARIABLES //\n\nvar debug = logger( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function' ;\nimport isCollection from '@stdlib/assert-is-collection' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport PINF from '@stdlib/constants-float64-pinf' ;\nimport validate from './validate.js' ;\nimport limit from './limit.js' ;\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0id43', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '0idBO', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0id43', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\n* @param {Collection} collection - input collection\n* @param {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file' ;\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right' ;\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport main from './main.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly","main"],"mappings":";;u2BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUR,EAAKK,SAGnDF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASR,EAAKS,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASP,GAkBzC,KC/CIU,SAkBJ,SAASF,EAAOG,EAAYC,EAAKb,EAAMc,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAAa,KAHbF,EAAMP,EAAWU,QAKhB,OAAOP,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMnB,EAAKS,MACTU,EAEAnB,EAAKS,MAGZE,EAAO,0BAA2BG,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdd,EAAO,kBAAmBiB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,GAPC,CAQD,CA5BDhB,EAAO,6BADPS,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM9B,EAAKI,QAASS,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM9B,EAAKI,QAASS,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM9B,EAAKI,QAASS,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJd,EAAO,2BAA4Bc,EAAMM,SAClChB,EAAMU,KAEdT,GAAS,EAEJI,EAAM,EACHG,IAEHP,IAAUG,EAEPJ,EAAM,KAAMF,QAFpB,EAIA,CACF,CCxCA,SAASmB,EAAS/B,EAASa,GAC1B,IAAId,EACAiC,EACAC,EAGJ,GADAlC,EAAO,CAAA,EACFmC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMlC,EAAUC,EAAMC,GAErB,MAAMgC,EAEPC,EAAIpB,CACN,MACEoB,EAAIjC,EAEL,IAAMmC,EAAYF,GACjB,MAAM,IAAI3B,UAAWC,EAAQ,QAAS0B,IAUvC,YARqB,IAAhBlC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ4B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIL,UAAWC,EAAQ,QAASI,IAEvC,IAAMwB,EAAYrB,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,OAAON,EAAOG,EAAY2B,EAASvC,EAAMkC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,EACZ,GACD,CACF,CC1EA,SAASyB,EAAkB1B,EAAY2B,EAAStC,EAASa,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAS/B,EAAT+B,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAS/B,EAASa,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,EAC/C,CCnBA0B,EAAAC,EAAA,UAAAV"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index b524e83..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 5d03629ebc9c21e56ec3b979ede0883bb908fde5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Nov 2022 07:42:54 +0000 Subject: [PATCH 031/147] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 781 ---- .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 - .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 47 +- benchmark/benchmark.factory.js | 73 - benchmark/benchmark.js | 160 - branches.md | 53 - docs/repl.txt | 224 -- docs/types/test.ts | 166 - examples/index.js | 55 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 165 - lib/index.js | 77 - lib/limit.js | 142 - lib/main.js | 96 - lib/validate.js | 80 - package.json | 64 +- stats.html | 4044 +++++++++++++++++++++ test/test.factory.js | 1095 ------ test/test.js | 38 - test/test.main.js | 1035 ------ test/test.validate.js | 181 - 44 files changed, 4075 insertions(+), 6652 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/limit.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 7776ec3..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-11-03T21:57:10.586Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1e08946..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 663f5df..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 45a5053..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '37 1 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 37ddb4f..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,781 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -447,7 +446,7 @@ reduceRightAsync( files, acc, read, done ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -515,11 +514,11 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right +[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right/tree/esm -[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce +[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/tree/esm diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 46d8b83..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var reduceRightAsync; - var arr; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - reduceRightAsync = factory( onItem ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - var acc; - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 6ad0714..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var reduceRightAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=false', function benchmark( b ) { - var opts; - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'series': false - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var arr; - var len; - var acc; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'limit': 3 - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 2aded98..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right" -click B href "https://github.com/stdlib-js/utils-async-reduce-right/tree/main" -click C href "https://github.com/stdlib-js/utils-async-reduce-right/tree/production" -click D href "https://github.com/stdlib-js/utils-async-reduce-right/tree/esm" -click E href "https://github.com/stdlib-js/utils-async-reduce-right/tree/deno" -click F href "https://github.com/stdlib-js/utils-async-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right -[production-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3f22669..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,224 +0,0 @@ - -{{alias}}( collection, initial, [options,] reducer, done ) - Applies a function against an accumulator and each element in a collection - and returns the accumulated result, iterating from right to left. - - When invoked, `reducer` is provided a maximum of five arguments: - - - `accumulator`: accumulated value - - `value`: collection value - - `index`: collection index - - `collection`: the input collection - - `next`: a callback to be invoked after processing a collection `value` - - The actual number of provided arguments depends on function length. If - `reducer` accepts three arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `next` - - If `reducer` accepts four arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `index` - - `next` - - For every other `reducer` signature, `reducer` is provided all five - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `accumulator`: accumulated value - - If a provided function calls the `next` callback with a truthy `error` - argument, the function suspends execution and immediately calls the `done` - callback for subsequent `error` handling. - - Execution is *not* guaranteed to be asynchronous. To guarantee asynchrony, - 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`). - - The function does not support dynamic collection resizing. - - If provided an empty collection, the function invokes the `done` callback - with the `initial` value as the second argument. - - The function does not skip `undefined` elements. - - When processing collection elements concurrently, *beware* of race - conditions when updating an accumulator. This is especially true when an - accumulator is a primitive (e.g., a number). In general, prefer object - accumulators. - - Parameters - ---------- - collection: Array|TypedArray|Object - Input collection over which to iterate. If provided an object, the - object must be array-like (excluding strings and functions). - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - reducer: Function - The function to invoke for each element in a collection. - - done: Function - A callback invoked either upon processing all collection elements or - upon encountering an error. - - Examples - -------- - // Basic usage: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, fcn, done ) - 3000 - 2500 - 1000 - 6500 - - // Limit number of concurrent invocations: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'limit': 2 }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 2500 - 3000 - 1000 - 6500 - - // Process concurrently: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'series': false }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 1000 - 2500 - 3000 - 6500 - - -{{alias}}.factory( [options,] fcn ) - Returns a function which applies a function against an accumulator and each - element in a collection and returns the accumulated result, iterating from - right to left. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - fcn: Function - The function to invoke for each element in a collection. - - Returns - ------- - out: Function - A function which invokes a function for each element in a collection. - - Examples - -------- - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > var opts = { 'series': false }; - > var f = {{alias}}.factory( opts, fcn ); - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > f( arr, acc, done ) - 1000 - 2500 - 3000 - 6500 - > acc = { 'sum': 0 }; - > arr = [ 1000, 1500, 2000 ]; - > f( arr, acc, done ) - 1000 - 1500 - 2000 - 4500 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 143a132..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,166 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unsafe-any */ - -import reduceRightAsync = require( './index' ); - -const reducer = ( acc: any, value: number, index: number, next: Function ) => { - acc.sum += value; - if ( index === void 0 ) { - throw new Error( '`index` is missing.' ); - } - next( null, acc ); -}; - -const done = ( error: Error | null, acc: any ) => { - if ( error ) { - throw error; - } - if ( acc === void 0 ) { - throw new Error( '`acc` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( 2, acc, reducer, done ); // $ExpectError - reduceRightAsync( false, acc, reducer, done ); // $ExpectError - reduceRightAsync( true, acc, reducer, done ); // $ExpectError - reduceRightAsync( {}, acc, reducer, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a predicate argument which is not a predicate function... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 2, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, false, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, true, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 'abc', done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, [], done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a done callback argument which is not a function having a supported signature... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 2 ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, false ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, true ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 'abc' ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, {} ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, [] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const acc = { 'sum': 0 }; - reduceRightAsync(); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, reducer, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - reduceRightAsync.factory( reducer ); // $ExpectType FactoryFunction - reduceRightAsync.factory( { 'series': true }, reducer ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - reduceRightAsync.factory( [], reducer ); // $ExpectError - reduceRightAsync.factory( 123, reducer ); // $ExpectError - reduceRightAsync.factory( 'abc', reducer ); // $ExpectError - reduceRightAsync.factory( false, reducer ); // $ExpectError - reduceRightAsync.factory( true, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not a predicate function... -{ - reduceRightAsync.factory( {} ); // $ExpectError - reduceRightAsync.factory( true ); // $ExpectError - reduceRightAsync.factory( false ); // $ExpectError - reduceRightAsync.factory( {}, 123 ); // $ExpectError - reduceRightAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1( 12, acc, done ); // $ExpectError - fcn1( true, acc, done ); // $ExpectError - fcn1( false, acc, done ); // $ExpectError - fcn1( {}, acc, done ); // $ExpectError - - fcn1( [ 3000, 2500, 1000 ], acc, 12 ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, true ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, false ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, '5' ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, {} ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, [] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1(); // $ExpectError - fcn1( [ 3000, 2500, 1000 ] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - reduceRightAsync.factory( { 'limit': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': true }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': false }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - reduceRightAsync.factory( { 'series': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': 12 }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - reduceRightAsync.factory(); // $ExpectError - reduceRightAsync.factory( {}, reducer, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index dd64345..0000000 --- a/examples/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var resolve = require( 'path' ).resolve; -var readFile = require( '@stdlib/fs-read-file' ); -var reduceRightAsync = require( './../lib' ); - -var files = [ - resolve( __dirname, '..', 'package.json' ), - resolve( __dirname, '..', 'README.md' ) -]; - -function done( error, acc ) { - if ( error ) { - throw error; - } - console.log( acc.count ); -} - -function read( acc, file, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( file, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( null, acc ); - } - acc.count += 1; - next( null, acc ); - } -} - -var acc = { - 'count': 0 -}; -reduceRightAsync( files, acc, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index b19e443..9dc0658 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { Collection } from '@stdlib/types/object'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..801bbde --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.8-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";function m(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("0id30","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!d(e.limit))?new TypeError(r("0id3b","limit",e.limit)):null):new TypeError(r("0id2h",t))}function c(e){var t=e.default;if("function"==typeof t){var i=function(){return t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var f=c(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function p(e,t,i,r,s){var n,o,l,d,m,c;if(d=e.length,f("Collection length: %d",d),0===d)return f("Finished processing a collection."),s(null,t);for(l=d0&&p();function p(){function s(e,i){if(!o){if(e)return o=!0,u(e);f("Accumulator: %s",JSON.stringify(i)),t=i,u()}}f("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function u(e){return e?(f("Encountered an error: %s",e.message),s(e)):(f("Processed %d of %d collection elements.",n+=1,d),m>0?p():n===d?(f("Finished processing a collection."),s(null,t)):void 0)}}function u(e,n){var o,l,d;if(o={},arguments.length>1){if(l=m(o,e))throw l;d=n}else d=e;if(!t(d))throw new TypeError(r("0id43",d));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=s),c;function c(e,s,n){if(!i(e))throw new TypeError(r("0idBO",e));if(!t(n))throw new TypeError(r("0id43",n));return p(e,s,o,d,(function(e,t){if(e)return n(e);n(null,t)}))}}function h(e,t,i,r,s){if(arguments.length<5)return u(i)(e,t,r);u(i,r)(e,t,s)}e(h,"factory",u);export{h as default,u as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..542ae0b --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean' ;\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\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( '0id2h', 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( '0id30', '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( '0id3b', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function' ;\nimport isCollection from '@stdlib/assert-is-collection' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport PINF from '@stdlib/constants-float64-pinf' ;\nimport validate from './validate.js' ;\nimport limit from './limit.js' ;\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0id43', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '0idBO', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0id43', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\n* @param {Collection} collection - input collection\n* @param {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file' ;\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right' ;\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport main from './main.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","logger","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly","main"],"mappings":";;u2BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUR,EAAKK,SAGnDF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASR,EAAKS,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASP,GAkBzC,0WC/CIU,uDAAQC,CAAQ,4BAkBpB,SAASH,EAAOI,EAAYC,EAAKd,EAAMe,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMP,EAAWU,OACjBZ,EAAO,wBAAyBS,GAEnB,IAARA,EAEJ,OADAT,EAAO,qCACAK,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAEZE,EAAO,wBAAyBQ,GAChCR,EAAO,0BAA2BI,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdf,EAAO,kBAAmBkB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,GAPC,CAQD,CA5BDjB,EAAO,6BADPU,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJf,EAAO,2BAA4Be,EAAMM,SAClChB,EAAMU,KAGdf,EAAO,0CADPM,GAAS,EACgDG,GACpDC,EAAM,EACHG,IAEHP,IAAUG,GACdT,EAAO,qCACAK,EAAM,KAAMF,SAFpB,EAIA,CACF,CCxCA,SAASmB,EAAShC,EAASc,GAC1B,IAAIf,EACAkC,EACAC,EAGJ,GADAnC,EAAO,CAAA,EACFoC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMnC,EAAUC,EAAMC,GAErB,MAAMiC,EAEPC,EAAIpB,CACN,MACEoB,EAAIlC,EAEL,IAAMoC,EAAYF,GACjB,MAAM,IAAI5B,UAAWC,EAAQ,QAAS2B,IAUvC,YARqB,IAAhBnC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ6B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIN,UAAWC,EAAQ,QAASK,IAEvC,IAAMwB,EAAYrB,GACjB,MAAM,IAAIT,UAAWC,EAAQ,QAASQ,IAEvC,OAAOP,EAAOI,EAAY2B,EAASxC,EAAMmC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,EACZ,GACD,CACF,CC1EA,SAASyB,EAAkB1B,EAAY2B,EAASvC,EAASc,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAShC,EAATgC,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAShC,EAASc,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,EAC/C,CCnBA0B,EAAAC,EAAA,UAAAV"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 6d67be2..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var validate = require( './validate.js' ); -var limit = require( './limit.js' ); - - -// MAIN // - -/** -* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} last argument must be a function -* @returns {Function} function which invokes the provided function once for each element in a collection -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error, data ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var opts = { -* 'series': false -* }; -* -* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: -* var reduceRightAsync = factory( opts, read ); -* -* // Create a collection over which to iterate: -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* // Define a callback which handles errors: -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* // Run `read` for each element in `files`: -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, done ); -*/ -function factory( options, fcn ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = fcn; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '0id43', f ) ); - } - if ( opts.series === void 0 && opts.limit === void 0 ) { - opts.series = true; - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return reduceRightAsync; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * @private - * @param {Collection} collection - input collection - * @param {*} initial - initial value - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be a collection - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function reduceRightAsync( collection, initial, done ) { - if ( !isCollection( collection ) ) { - throw new TypeError( format( '0idBO', collection ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '0id43', done ) ); - } - return limit( collection, initial, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {*} [acc] - accumulated value - * @returns {void} - */ - function clbk( error, acc ) { - if ( error ) { - return done( error ); - } - done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ae657ff..0000000 --- a/lib/index.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* @module @stdlib/utils-async-reduce-right -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' ); -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/limit.js b/lib/limit.js deleted file mode 100644 index cdb60af..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); - - -// VARIABLES // - -var debug = logger( 'reduce-right-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each element in a collection, limiting the number of concurrently pending functions and iterating from right to left. -* -* @private -* @param {Collection} collection - input collection -* @param {*} acc - initial value -* @param {Options} opts - function options -* @param {*} [opts.thisArg] - execution context -* @param {PositiveInteger} [opts.limit] - maximum number of pending function invocations -* @param {Function} fcn - function to invoke -* @param {Callback} done - function to invoke upon completion or upon encountering an error -* @returns {void} -*/ -function limit( collection, acc, opts, fcn, done ) { - var count; - var flg; - var lim; - var len; - var idx; - var i; - - len = collection.length; - debug( 'Collection length: %d', len ); - - if ( len === 0 ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - count = 0; - idx = len; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all collection elements... - if ( idx > 0 ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next element in a collection. - * - * @private - */ - function next() { - idx -= 1; - debug( 'Collection element %d: %s.', idx, JSON.stringify( collection[ idx ] ) ); - if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], cb ); - } else if ( fcn.length === 4 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, cb ); - } else { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len - } - /** - * Callback invoked once a provided function finishes processing a collection element. - * - * @private - * @param {*} [error] - error - * @param {*} [result] - accumulation result - * @returns {void} - */ - function cb( error, result ) { - if ( flg ) { - // Prevent further processing of collection elements: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Accumulator: %s', JSON.stringify( result ) ); - acc = result; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next collection element. - * - * @private - * @param {*} [error] - error - * @returns {void} - */ - function clbk( error ) { - if ( error ) { - debug( 'Encountered an error: %s', error.message ); - return done( error ); - } - count += 1; - debug( 'Processed %d of %d collection elements.', count, len ); - if ( idx > 0 ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 9f016bf..0000000 --- a/lib/main.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param {Collection} collection - input collection -* @param {*} initial - initial value -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} second-to-last argument must be a function -* @throws {TypeError} last argument must be a function -* @returns {void} -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -function reduceRightAsync( collection, initial, options, fcn, done ) { - if ( arguments.length < 5 ) { - return factory( options )( collection, initial, fcn ); - } - factory( options, fcn )( collection, initial, done ); -} - - -// EXPORTS // - -module.exports = reduceRightAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 6292663..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @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 -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'thisArg': {}, -* 'series': false, -* 'limit': 10 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '0id2h', options ) ); - } - if ( hasOwnProp( options, 'thisArg' ) ) { - opts.thisArg = options.thisArg; - } - if ( hasOwnProp( options, 'series' ) ) { - opts.series = options.series; - if ( !isBoolean( opts.series ) ) { - return new TypeError( format( '0id30', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '0id3b', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 005e6d8..55f16d9 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.8", "description": "Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,43 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-boolean": "^0.0.x", - "@stdlib/assert-is-collection": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/assert-is-positive-integer": "^0.0.x", - "@stdlib/constants-float64-pinf": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/constants-float64-eps": "^0.0.x", - "@stdlib/fs-read-file": "^0.0.x", - "@stdlib/utils-noop": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..3148065 --- /dev/null +++ b/stats.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 8244931..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1095 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( {}, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, next ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - factory( opts, next ); - }; - } -}); - -tape( 'the function returns a function (no options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided a collection (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a collection (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (1 argument)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (2 arguments)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with five arguments', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn() { - var value; - var next; - var acc; - var k; - - acc = arguments[ 0 ]; - value = arguments[ 1 ]; - k = arguments[ 2 ]; - next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( k, i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the returned function supports processing collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements concurrently', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 100, 250, 300 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements sequentially (limit = 1)', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of collection elements which are processed at any one time', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 250, 300, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 250, 100, 300 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var reduceRightAsync; - var arr; - - reduceRightAsync = factory( fcn ); - arr = []; - - reduceRightAsync( arr, 0, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var reduceRightAsync; - var obj; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = []; - obj = {}; - reduceRightAsync( arr, obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - i = 0; - - reduceRightAsync( arr, {}, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, acc ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the returned function does not skip empty elements', function test( t ) { - var reduceRightAsync; - var expected; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index f273a40..0000000 --- a/test/test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof reduceRightAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 1893240..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1035 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a collection', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (no options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, next, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, 0 ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - reduceRightAsync( [ 1, 2, 3 ], 0, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (1 argument)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (2 arguments)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with five arguments', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn() { - var next; - var acc; - var v; - - next = arguments[ 4 ]; - acc = arguments[ 0 ]; - v = arguments[ 1 ]; - - i -= 1; - j += 1; - - t.strictEqual( v, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, v ); - - function onTimeout() { - acc.sum += v; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'by default, the function processes collection elements sequentially', function test( t ) { - var values; - var count; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements concurrently', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 100, 250, 300 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': true - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially (limit = 1)', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var arr; - var ctx; - - arr = [ 3, 2, 1 ]; - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 3, 2, 1 ]; - opts = { - 'series': true - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 250, 100, 300 ]; - opts = { - 'limit': 2 - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var arr = []; - reduceRightAsync( arr, 0, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var arr = []; - var obj = {}; - - reduceRightAsync( arr, obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - arr = [ 3, 2, 1 ]; - i = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, value ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the function does not skip empty elements', function test( t ) { - var expected; - var arr; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, fcn, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 7660838..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,181 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `limit` option which is not a positive integer', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - -5, - 0, - 3.14, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'limit': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `series` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'series': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function accepts any value for the `thisArg` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'thisArg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err, null, 'returns null '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'thisArg': {}, - 'series': false, - 'limit': 10 - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From 90bb40b70a398a34adaacb45af9437422e92aebb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 03:59:44 +0000 Subject: [PATCH 032/147] Transform error messages --- lib/factory.js | 8 ++++---- lib/validate.js | 8 ++++---- package.json | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index a627d69..6d67be2 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -22,7 +22,7 @@ var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var PINF = require( '@stdlib/constants-float64-pinf' ); var validate = require( './validate.js' ); var limit = require( './limit.js' ); @@ -110,7 +110,7 @@ function factory( options, fcn ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '0id43', f ) ); } if ( opts.series === void 0 && opts.limit === void 0 ) { opts.series = true; @@ -135,10 +135,10 @@ function factory( options, fcn ) { */ function reduceRightAsync( collection, initial, done ) { if ( !isCollection( collection ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a collection. Value: `%s`.', collection ) ); + throw new TypeError( format( '0idBO', collection ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '0id43', done ) ); } return limit( collection, initial, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index 9ba927e..6292663 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,7 +54,7 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0id2h', options ) ); } if ( hasOwnProp( options, 'thisArg' ) ) { opts.thisArg = options.thisArg; @@ -62,13 +62,13 @@ function validate( opts, options ) { if ( hasOwnProp( options, 'series' ) ) { opts.series = options.series; if ( !isBoolean( opts.series ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'series', opts.series ) ); + return new TypeError( format( '0id30', 'series', opts.series ) ); } } if ( hasOwnProp( options, 'limit' ) ) { opts.limit = options.limit; if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'limit', opts.limit ) ); + return new TypeError( format( '0id3b', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index 593bde1..de893c4 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-plain-object": "^0.0.x", "@stdlib/assert-is-positive-integer": "^0.0.x", "@stdlib/constants-float64-pinf": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x", "debug": "^2.6.9" From 7286c48b5170134c54ac0af559f1464d0863de53 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 17:30:42 +0000 Subject: [PATCH 033/147] Remove files --- index.d.ts | 415 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4464 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 9dc0658..0000000 --- a/index.d.ts +++ /dev/null @@ -1,415 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Collection } from '@stdlib/types/object'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * The maximum number of pending invocations at any one time. - */ - limit?: number; - - /** - * Boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection (default: true). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback function. -*/ -type Nullary = () => void; - -/** -* Callback function. -* -* @param error - encountered error or null -*/ -type Unary = ( error: Error | null ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Binary = ( error: Error | null, accumulator: any ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param next - a callback to be invoked after processing a collection `value` -*/ -type TernaryReducer = ( accumulator: any, value: any, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuaternaryReducer = ( accumulator: any, value: any, index: number, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuinaryReducer = ( accumulator: any, value: any, index: number, collection: Collection, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type Reducer = TernaryReducer | QuaternaryReducer | QuinaryReducer; - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result. -* -* @param collection - input collection -* @param initial - initial value -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( collection: Collection, initial: any, done: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Interface for `reduceRightAsync`. -*/ -interface ReduceRightAsync { - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, {}, read, done ); - */ - ( collection: Collection, initial: any, options: Options, reducer: Reducer, done: Callback ): void; // tslint-disable-line max-line-length - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, read, done ); - */ - ( collection: Collection, initial: any, reducer: Reducer, done: Callback ): void; // tslint-disable-line max-line-length - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @throws must provide valid options - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var opts = { - * 'series': false - * }; - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( opts, read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( options: Options, reducer: Reducer ): FactoryFunction; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param reducer - function to invoke for each element in a collection - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( reducer: Reducer ): FactoryFunction; -} - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param collection - input collection -* @param initial - initial value -* @param options - function options -* @param options.thisArg - execution context -* @param options.limit - maximum number of pending invocations at any one time -* @param 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 (default: true) -* @param reducer - function to invoke for each element in a collection -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( `@stdlib/fs/read-file` ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -declare var reduceRightAsync: ReduceRightAsync; - - -// EXPORTS // - -export = reduceRightAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 801bbde..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.8-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";function m(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("0id30","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!d(e.limit))?new TypeError(r("0id3b","limit",e.limit)):null):new TypeError(r("0id2h",t))}function c(e){var t=e.default;if("function"==typeof t){var i=function(){return t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var f=c(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function p(e,t,i,r,s){var n,o,l,d,m,c;if(d=e.length,f("Collection length: %d",d),0===d)return f("Finished processing a collection."),s(null,t);for(l=d0&&p();function p(){function s(e,i){if(!o){if(e)return o=!0,u(e);f("Accumulator: %s",JSON.stringify(i)),t=i,u()}}f("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function u(e){return e?(f("Encountered an error: %s",e.message),s(e)):(f("Processed %d of %d collection elements.",n+=1,d),m>0?p():n===d?(f("Finished processing a collection."),s(null,t)):void 0)}}function u(e,n){var o,l,d;if(o={},arguments.length>1){if(l=m(o,e))throw l;d=n}else d=e;if(!t(d))throw new TypeError(r("0id43",d));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=s),c;function c(e,s,n){if(!i(e))throw new TypeError(r("0idBO",e));if(!t(n))throw new TypeError(r("0id43",n));return p(e,s,o,d,(function(e,t){if(e)return n(e);n(null,t)}))}}function h(e,t,i,r,s){if(arguments.length<5)return u(i)(e,t,r);u(i,r)(e,t,s)}e(h,"factory",u);export{h as default,u as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 542ae0b..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean' ;\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\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( '0id2h', 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( '0id30', '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( '0id3b', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function' ;\nimport isCollection from '@stdlib/assert-is-collection' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport PINF from '@stdlib/constants-float64-pinf' ;\nimport validate from './validate.js' ;\nimport limit from './limit.js' ;\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0id43', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '0idBO', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0id43', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\n* @param {Collection} collection - input collection\n* @param {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file' ;\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right' ;\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport main from './main.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","logger","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly","main"],"mappings":";;u2BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUR,EAAKK,SAGnDF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASR,EAAKS,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASP,GAkBzC,0WC/CIU,uDAAQC,CAAQ,4BAkBpB,SAASH,EAAOI,EAAYC,EAAKd,EAAMe,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMP,EAAWU,OACjBZ,EAAO,wBAAyBS,GAEnB,IAARA,EAEJ,OADAT,EAAO,qCACAK,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAEZE,EAAO,wBAAyBQ,GAChCR,EAAO,0BAA2BI,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdf,EAAO,kBAAmBkB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,GAPC,CAQD,CA5BDjB,EAAO,6BADPU,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJf,EAAO,2BAA4Be,EAAMM,SAClChB,EAAMU,KAGdf,EAAO,0CADPM,GAAS,EACgDG,GACpDC,EAAM,EACHG,IAEHP,IAAUG,GACdT,EAAO,qCACAK,EAAM,KAAMF,SAFpB,EAIA,CACF,CCxCA,SAASmB,EAAShC,EAASc,GAC1B,IAAIf,EACAkC,EACAC,EAGJ,GADAnC,EAAO,CAAA,EACFoC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMnC,EAAUC,EAAMC,GAErB,MAAMiC,EAEPC,EAAIpB,CACN,MACEoB,EAAIlC,EAEL,IAAMoC,EAAYF,GACjB,MAAM,IAAI5B,UAAWC,EAAQ,QAAS2B,IAUvC,YARqB,IAAhBnC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ6B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIN,UAAWC,EAAQ,QAASK,IAEvC,IAAMwB,EAAYrB,GACjB,MAAM,IAAIT,UAAWC,EAAQ,QAASQ,IAEvC,OAAOP,EAAOI,EAAY2B,EAASxC,EAAMmC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,EACZ,GACD,CACF,CC1EA,SAASyB,EAAkB1B,EAAY2B,EAASvC,EAASc,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAShC,EAATgC,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAShC,EAASc,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,EAC/C,CCnBA0B,EAAAC,EAAA,UAAAV"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 3148065..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From da22e3a907eccc764e81f65d3dc4c1439ab582e3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 17:31:19 +0000 Subject: [PATCH 034/147] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 781 ---- .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 183 - .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 47 +- benchmark/benchmark.factory.js | 73 - benchmark/benchmark.js | 160 - branches.md | 53 - docs/repl.txt | 224 -- docs/types/test.ts | 166 - examples/index.js | 55 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 165 - lib/index.js | 77 - lib/limit.js | 142 - lib/main.js | 96 - lib/validate.js | 80 - package.json | 64 +- stats.html | 4044 +++++++++++++++++++++ test/test.factory.js | 1095 ------ test/test.js | 38 - test/test.main.js | 1035 ------ test/test.validate.js | 181 - 44 files changed, 4075 insertions(+), 6657 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/limit.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 6466484..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-12-01T01:47:00.669Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1e08946..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 663f5df..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 45a5053..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '37 1 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 37ddb4f..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,781 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -447,7 +446,7 @@ reduceRightAsync( files, acc, read, done ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -515,11 +514,11 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right +[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right/tree/esm -[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce +[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/tree/esm diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 46d8b83..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var reduceRightAsync; - var arr; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - reduceRightAsync = factory( onItem ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - var acc; - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 6ad0714..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var reduceRightAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=false', function benchmark( b ) { - var opts; - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'series': false - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var arr; - var len; - var acc; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'limit': 3 - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 2aded98..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right" -click B href "https://github.com/stdlib-js/utils-async-reduce-right/tree/main" -click C href "https://github.com/stdlib-js/utils-async-reduce-right/tree/production" -click D href "https://github.com/stdlib-js/utils-async-reduce-right/tree/esm" -click E href "https://github.com/stdlib-js/utils-async-reduce-right/tree/deno" -click F href "https://github.com/stdlib-js/utils-async-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right -[production-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3f22669..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,224 +0,0 @@ - -{{alias}}( collection, initial, [options,] reducer, done ) - Applies a function against an accumulator and each element in a collection - and returns the accumulated result, iterating from right to left. - - When invoked, `reducer` is provided a maximum of five arguments: - - - `accumulator`: accumulated value - - `value`: collection value - - `index`: collection index - - `collection`: the input collection - - `next`: a callback to be invoked after processing a collection `value` - - The actual number of provided arguments depends on function length. If - `reducer` accepts three arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `next` - - If `reducer` accepts four arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `index` - - `next` - - For every other `reducer` signature, `reducer` is provided all five - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `accumulator`: accumulated value - - If a provided function calls the `next` callback with a truthy `error` - argument, the function suspends execution and immediately calls the `done` - callback for subsequent `error` handling. - - Execution is *not* guaranteed to be asynchronous. To guarantee asynchrony, - 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`). - - The function does not support dynamic collection resizing. - - If provided an empty collection, the function invokes the `done` callback - with the `initial` value as the second argument. - - The function does not skip `undefined` elements. - - When processing collection elements concurrently, *beware* of race - conditions when updating an accumulator. This is especially true when an - accumulator is a primitive (e.g., a number). In general, prefer object - accumulators. - - Parameters - ---------- - collection: Array|TypedArray|Object - Input collection over which to iterate. If provided an object, the - object must be array-like (excluding strings and functions). - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - reducer: Function - The function to invoke for each element in a collection. - - done: Function - A callback invoked either upon processing all collection elements or - upon encountering an error. - - Examples - -------- - // Basic usage: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, fcn, done ) - 3000 - 2500 - 1000 - 6500 - - // Limit number of concurrent invocations: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'limit': 2 }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 2500 - 3000 - 1000 - 6500 - - // Process concurrently: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'series': false }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 1000 - 2500 - 3000 - 6500 - - -{{alias}}.factory( [options,] fcn ) - Returns a function which applies a function against an accumulator and each - element in a collection and returns the accumulated result, iterating from - right to left. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - fcn: Function - The function to invoke for each element in a collection. - - Returns - ------- - out: Function - A function which invokes a function for each element in a collection. - - Examples - -------- - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > var opts = { 'series': false }; - > var f = {{alias}}.factory( opts, fcn ); - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > f( arr, acc, done ) - 1000 - 2500 - 3000 - 6500 - > acc = { 'sum': 0 }; - > arr = [ 1000, 1500, 2000 ]; - > f( arr, acc, done ) - 1000 - 1500 - 2000 - 4500 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 143a132..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,166 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unsafe-any */ - -import reduceRightAsync = require( './index' ); - -const reducer = ( acc: any, value: number, index: number, next: Function ) => { - acc.sum += value; - if ( index === void 0 ) { - throw new Error( '`index` is missing.' ); - } - next( null, acc ); -}; - -const done = ( error: Error | null, acc: any ) => { - if ( error ) { - throw error; - } - if ( acc === void 0 ) { - throw new Error( '`acc` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( 2, acc, reducer, done ); // $ExpectError - reduceRightAsync( false, acc, reducer, done ); // $ExpectError - reduceRightAsync( true, acc, reducer, done ); // $ExpectError - reduceRightAsync( {}, acc, reducer, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a predicate argument which is not a predicate function... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 2, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, false, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, true, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 'abc', done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, [], done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a done callback argument which is not a function having a supported signature... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 2 ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, false ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, true ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 'abc' ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, {} ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, [] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const acc = { 'sum': 0 }; - reduceRightAsync(); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, reducer, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - reduceRightAsync.factory( reducer ); // $ExpectType FactoryFunction - reduceRightAsync.factory( { 'series': true }, reducer ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - reduceRightAsync.factory( [], reducer ); // $ExpectError - reduceRightAsync.factory( 123, reducer ); // $ExpectError - reduceRightAsync.factory( 'abc', reducer ); // $ExpectError - reduceRightAsync.factory( false, reducer ); // $ExpectError - reduceRightAsync.factory( true, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not a predicate function... -{ - reduceRightAsync.factory( {} ); // $ExpectError - reduceRightAsync.factory( true ); // $ExpectError - reduceRightAsync.factory( false ); // $ExpectError - reduceRightAsync.factory( {}, 123 ); // $ExpectError - reduceRightAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1( 12, acc, done ); // $ExpectError - fcn1( true, acc, done ); // $ExpectError - fcn1( false, acc, done ); // $ExpectError - fcn1( {}, acc, done ); // $ExpectError - - fcn1( [ 3000, 2500, 1000 ], acc, 12 ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, true ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, false ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, '5' ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, {} ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, [] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1(); // $ExpectError - fcn1( [ 3000, 2500, 1000 ] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - reduceRightAsync.factory( { 'limit': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': true }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': false }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - reduceRightAsync.factory( { 'series': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': 12 }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - reduceRightAsync.factory(); // $ExpectError - reduceRightAsync.factory( {}, reducer, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index dd64345..0000000 --- a/examples/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var resolve = require( 'path' ).resolve; -var readFile = require( '@stdlib/fs-read-file' ); -var reduceRightAsync = require( './../lib' ); - -var files = [ - resolve( __dirname, '..', 'package.json' ), - resolve( __dirname, '..', 'README.md' ) -]; - -function done( error, acc ) { - if ( error ) { - throw error; - } - console.log( acc.count ); -} - -function read( acc, file, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( file, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( null, acc ); - } - acc.count += 1; - next( null, acc ); - } -} - -var acc = { - 'count': 0 -}; -reduceRightAsync( files, acc, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index b19e443..9dc0658 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { Collection } from '@stdlib/types/object'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..801bbde --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.8-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";function m(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("0id30","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!d(e.limit))?new TypeError(r("0id3b","limit",e.limit)):null):new TypeError(r("0id2h",t))}function c(e){var t=e.default;if("function"==typeof t){var i=function(){return t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var f=c(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function p(e,t,i,r,s){var n,o,l,d,m,c;if(d=e.length,f("Collection length: %d",d),0===d)return f("Finished processing a collection."),s(null,t);for(l=d0&&p();function p(){function s(e,i){if(!o){if(e)return o=!0,u(e);f("Accumulator: %s",JSON.stringify(i)),t=i,u()}}f("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function u(e){return e?(f("Encountered an error: %s",e.message),s(e)):(f("Processed %d of %d collection elements.",n+=1,d),m>0?p():n===d?(f("Finished processing a collection."),s(null,t)):void 0)}}function u(e,n){var o,l,d;if(o={},arguments.length>1){if(l=m(o,e))throw l;d=n}else d=e;if(!t(d))throw new TypeError(r("0id43",d));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=s),c;function c(e,s,n){if(!i(e))throw new TypeError(r("0idBO",e));if(!t(n))throw new TypeError(r("0id43",n));return p(e,s,o,d,(function(e,t){if(e)return n(e);n(null,t)}))}}function h(e,t,i,r,s){if(arguments.length<5)return u(i)(e,t,r);u(i,r)(e,t,s)}e(h,"factory",u);export{h as default,u as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..ae6782f --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '0id2h', 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( '0id30', '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( '0id3b', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0id43', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '0idBO', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0id43', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\n* @param {Collection} collection - input collection\n* @param {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","logger","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly","main"],"mappings":";;u2BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUR,EAAKK,SAGnDF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASR,EAAKS,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASP,GAkBzC,0WC/CIU,uDAAQC,CAAQ,4BAkBpB,SAASH,EAAOI,EAAYC,EAAKd,EAAMe,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMP,EAAWU,OACjBZ,EAAO,wBAAyBS,GAEnB,IAARA,EAEJ,OADAT,EAAO,qCACAK,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAEZE,EAAO,wBAAyBQ,GAChCR,EAAO,0BAA2BI,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdf,EAAO,kBAAmBkB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,GAPC,CAQD,CA5BDjB,EAAO,6BADPU,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJf,EAAO,2BAA4Be,EAAMM,SAClChB,EAAMU,KAGdf,EAAO,0CADPM,GAAS,EACgDG,GACpDC,EAAM,EACHG,IAEHP,IAAUG,GACdT,EAAO,qCACAK,EAAM,KAAMF,SAFpB,EAIA,CACF,CCxCA,SAASmB,EAAShC,EAASc,GAC1B,IAAIf,EACAkC,EACAC,EAGJ,GADAnC,EAAO,CAAA,EACFoC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMnC,EAAUC,EAAMC,GAErB,MAAMiC,EAEPC,EAAIpB,CACN,MACEoB,EAAIlC,EAEL,IAAMoC,EAAYF,GACjB,MAAM,IAAI5B,UAAWC,EAAQ,QAAS2B,IAUvC,YARqB,IAAhBnC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ6B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIN,UAAWC,EAAQ,QAASK,IAEvC,IAAMwB,EAAYrB,GACjB,MAAM,IAAIT,UAAWC,EAAQ,QAASQ,IAEvC,OAAOP,EAAOI,EAAY2B,EAASxC,EAAMmC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,EACZ,GACD,CACF,CC1EA,SAASyB,EAAkB1B,EAAY2B,EAASvC,EAASc,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAShC,EAATgC,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAShC,EAASc,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,EAC/C,CCnBA0B,EAAAC,EAAA,UAAAV"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 6d67be2..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var validate = require( './validate.js' ); -var limit = require( './limit.js' ); - - -// MAIN // - -/** -* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} last argument must be a function -* @returns {Function} function which invokes the provided function once for each element in a collection -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error, data ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var opts = { -* 'series': false -* }; -* -* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: -* var reduceRightAsync = factory( opts, read ); -* -* // Create a collection over which to iterate: -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* // Define a callback which handles errors: -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* // Run `read` for each element in `files`: -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, done ); -*/ -function factory( options, fcn ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = fcn; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '0id43', f ) ); - } - if ( opts.series === void 0 && opts.limit === void 0 ) { - opts.series = true; - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return reduceRightAsync; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * @private - * @param {Collection} collection - input collection - * @param {*} initial - initial value - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be a collection - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function reduceRightAsync( collection, initial, done ) { - if ( !isCollection( collection ) ) { - throw new TypeError( format( '0idBO', collection ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '0id43', done ) ); - } - return limit( collection, initial, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {*} [acc] - accumulated value - * @returns {void} - */ - function clbk( error, acc ) { - if ( error ) { - return done( error ); - } - done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ae657ff..0000000 --- a/lib/index.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* @module @stdlib/utils-async-reduce-right -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' ); -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/limit.js b/lib/limit.js deleted file mode 100644 index cdb60af..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); - - -// VARIABLES // - -var debug = logger( 'reduce-right-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each element in a collection, limiting the number of concurrently pending functions and iterating from right to left. -* -* @private -* @param {Collection} collection - input collection -* @param {*} acc - initial value -* @param {Options} opts - function options -* @param {*} [opts.thisArg] - execution context -* @param {PositiveInteger} [opts.limit] - maximum number of pending function invocations -* @param {Function} fcn - function to invoke -* @param {Callback} done - function to invoke upon completion or upon encountering an error -* @returns {void} -*/ -function limit( collection, acc, opts, fcn, done ) { - var count; - var flg; - var lim; - var len; - var idx; - var i; - - len = collection.length; - debug( 'Collection length: %d', len ); - - if ( len === 0 ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - count = 0; - idx = len; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all collection elements... - if ( idx > 0 ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next element in a collection. - * - * @private - */ - function next() { - idx -= 1; - debug( 'Collection element %d: %s.', idx, JSON.stringify( collection[ idx ] ) ); - if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], cb ); - } else if ( fcn.length === 4 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, cb ); - } else { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len - } - /** - * Callback invoked once a provided function finishes processing a collection element. - * - * @private - * @param {*} [error] - error - * @param {*} [result] - accumulation result - * @returns {void} - */ - function cb( error, result ) { - if ( flg ) { - // Prevent further processing of collection elements: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Accumulator: %s', JSON.stringify( result ) ); - acc = result; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next collection element. - * - * @private - * @param {*} [error] - error - * @returns {void} - */ - function clbk( error ) { - if ( error ) { - debug( 'Encountered an error: %s', error.message ); - return done( error ); - } - count += 1; - debug( 'Processed %d of %d collection elements.', count, len ); - if ( idx > 0 ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 9f016bf..0000000 --- a/lib/main.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param {Collection} collection - input collection -* @param {*} initial - initial value -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} second-to-last argument must be a function -* @throws {TypeError} last argument must be a function -* @returns {void} -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -function reduceRightAsync( collection, initial, options, fcn, done ) { - if ( arguments.length < 5 ) { - return factory( options )( collection, initial, fcn ); - } - factory( options, fcn )( collection, initial, done ); -} - - -// EXPORTS // - -module.exports = reduceRightAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 6292663..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @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 -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'thisArg': {}, -* 'series': false, -* 'limit': 10 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '0id2h', options ) ); - } - if ( hasOwnProp( options, 'thisArg' ) ) { - opts.thisArg = options.thisArg; - } - if ( hasOwnProp( options, 'series' ) ) { - opts.series = options.series; - if ( !isBoolean( opts.series ) ) { - return new TypeError( format( '0id30', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '0id3b', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index de893c4..55f16d9 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.8", "description": "Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,43 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-boolean": "^0.0.x", - "@stdlib/assert-is-collection": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/assert-is-positive-integer": "^0.0.x", - "@stdlib/constants-float64-pinf": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/constants-float64-eps": "^0.0.x", - "@stdlib/fs-read-file": "^0.0.x", - "@stdlib/utils-noop": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "2.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..e34c2ba --- /dev/null +++ b/stats.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 8244931..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1095 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( {}, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, next ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - factory( opts, next ); - }; - } -}); - -tape( 'the function returns a function (no options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided a collection (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a collection (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (1 argument)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (2 arguments)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with five arguments', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn() { - var value; - var next; - var acc; - var k; - - acc = arguments[ 0 ]; - value = arguments[ 1 ]; - k = arguments[ 2 ]; - next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( k, i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the returned function supports processing collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements concurrently', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 100, 250, 300 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements sequentially (limit = 1)', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of collection elements which are processed at any one time', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 250, 300, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 250, 100, 300 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var reduceRightAsync; - var arr; - - reduceRightAsync = factory( fcn ); - arr = []; - - reduceRightAsync( arr, 0, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var reduceRightAsync; - var obj; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = []; - obj = {}; - reduceRightAsync( arr, obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - i = 0; - - reduceRightAsync( arr, {}, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, acc ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the returned function does not skip empty elements', function test( t ) { - var reduceRightAsync; - var expected; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index f273a40..0000000 --- a/test/test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof reduceRightAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 1893240..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1035 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a collection', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (no options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, next, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, 0 ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - reduceRightAsync( [ 1, 2, 3 ], 0, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (1 argument)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (2 arguments)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with five arguments', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn() { - var next; - var acc; - var v; - - next = arguments[ 4 ]; - acc = arguments[ 0 ]; - v = arguments[ 1 ]; - - i -= 1; - j += 1; - - t.strictEqual( v, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, v ); - - function onTimeout() { - acc.sum += v; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'by default, the function processes collection elements sequentially', function test( t ) { - var values; - var count; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements concurrently', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 100, 250, 300 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': true - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially (limit = 1)', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var arr; - var ctx; - - arr = [ 3, 2, 1 ]; - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 3, 2, 1 ]; - opts = { - 'series': true - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 250, 100, 300 ]; - opts = { - 'limit': 2 - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var arr = []; - reduceRightAsync( arr, 0, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var arr = []; - var obj = {}; - - reduceRightAsync( arr, obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - arr = [ 3, 2, 1 ]; - i = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, value ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the function does not skip empty elements', function test( t ) { - var expected; - var arr; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, fcn, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 7660838..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,181 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `limit` option which is not a positive integer', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - -5, - 0, - 3.14, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'limit': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `series` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'series': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function accepts any value for the `thisArg` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'thisArg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err, null, 'returns null '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'thisArg': {}, - 'series': false, - 'limit': 10 - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From 4504eb9963f9a794ffcec00ef6a340becbbee609 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Jan 2023 03:21:51 +0000 Subject: [PATCH 035/147] Transform error messages --- lib/factory.js | 8 ++++---- lib/validate.js | 8 ++++---- package.json | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index a627d69..6d67be2 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -22,7 +22,7 @@ var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var PINF = require( '@stdlib/constants-float64-pinf' ); var validate = require( './validate.js' ); var limit = require( './limit.js' ); @@ -110,7 +110,7 @@ function factory( options, fcn ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '0id43', f ) ); } if ( opts.series === void 0 && opts.limit === void 0 ) { opts.series = true; @@ -135,10 +135,10 @@ function factory( options, fcn ) { */ function reduceRightAsync( collection, initial, done ) { if ( !isCollection( collection ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a collection. Value: `%s`.', collection ) ); + throw new TypeError( format( '0idBO', collection ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '0id43', done ) ); } return limit( collection, initial, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index 9ba927e..6292663 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,7 +54,7 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0id2h', options ) ); } if ( hasOwnProp( options, 'thisArg' ) ) { opts.thisArg = options.thisArg; @@ -62,13 +62,13 @@ function validate( opts, options ) { if ( hasOwnProp( options, 'series' ) ) { opts.series = options.series; if ( !isBoolean( opts.series ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'series', opts.series ) ); + return new TypeError( format( '0id30', 'series', opts.series ) ); } } if ( hasOwnProp( options, 'limit' ) ) { opts.limit = options.limit; if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'limit', opts.limit ) ); + return new TypeError( format( '0id3b', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index ff5f76c..6587773 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-plain-object": "^0.0.x", "@stdlib/assert-is-positive-integer": "^0.0.x", "@stdlib/constants-float64-pinf": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x", "debug": "^2.6.9" From b09e52ed0a7cdbb5fc1c02134a24ee54b2ba6452 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Jan 2023 13:23:14 +0000 Subject: [PATCH 036/147] Remove files --- index.d.ts | 415 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4464 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 9dc0658..0000000 --- a/index.d.ts +++ /dev/null @@ -1,415 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Collection } from '@stdlib/types/object'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * The maximum number of pending invocations at any one time. - */ - limit?: number; - - /** - * Boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection (default: true). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback function. -*/ -type Nullary = () => void; - -/** -* Callback function. -* -* @param error - encountered error or null -*/ -type Unary = ( error: Error | null ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Binary = ( error: Error | null, accumulator: any ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param next - a callback to be invoked after processing a collection `value` -*/ -type TernaryReducer = ( accumulator: any, value: any, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuaternaryReducer = ( accumulator: any, value: any, index: number, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuinaryReducer = ( accumulator: any, value: any, index: number, collection: Collection, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type Reducer = TernaryReducer | QuaternaryReducer | QuinaryReducer; - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result. -* -* @param collection - input collection -* @param initial - initial value -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( collection: Collection, initial: any, done: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Interface for `reduceRightAsync`. -*/ -interface ReduceRightAsync { - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, {}, read, done ); - */ - ( collection: Collection, initial: any, options: Options, reducer: Reducer, done: Callback ): void; // tslint-disable-line max-line-length - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, read, done ); - */ - ( collection: Collection, initial: any, reducer: Reducer, done: Callback ): void; // tslint-disable-line max-line-length - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @throws must provide valid options - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var opts = { - * 'series': false - * }; - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( opts, read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( options: Options, reducer: Reducer ): FactoryFunction; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param reducer - function to invoke for each element in a collection - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( reducer: Reducer ): FactoryFunction; -} - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param collection - input collection -* @param initial - initial value -* @param options - function options -* @param options.thisArg - execution context -* @param options.limit - maximum number of pending invocations at any one time -* @param 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 (default: true) -* @param reducer - function to invoke for each element in a collection -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( `@stdlib/fs/read-file` ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -declare var reduceRightAsync: ReduceRightAsync; - - -// EXPORTS // - -export = reduceRightAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 801bbde..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.8-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";function m(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("0id30","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!d(e.limit))?new TypeError(r("0id3b","limit",e.limit)):null):new TypeError(r("0id2h",t))}function c(e){var t=e.default;if("function"==typeof t){var i=function(){return t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var f=c(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function p(e,t,i,r,s){var n,o,l,d,m,c;if(d=e.length,f("Collection length: %d",d),0===d)return f("Finished processing a collection."),s(null,t);for(l=d0&&p();function p(){function s(e,i){if(!o){if(e)return o=!0,u(e);f("Accumulator: %s",JSON.stringify(i)),t=i,u()}}f("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function u(e){return e?(f("Encountered an error: %s",e.message),s(e)):(f("Processed %d of %d collection elements.",n+=1,d),m>0?p():n===d?(f("Finished processing a collection."),s(null,t)):void 0)}}function u(e,n){var o,l,d;if(o={},arguments.length>1){if(l=m(o,e))throw l;d=n}else d=e;if(!t(d))throw new TypeError(r("0id43",d));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=s),c;function c(e,s,n){if(!i(e))throw new TypeError(r("0idBO",e));if(!t(n))throw new TypeError(r("0id43",n));return p(e,s,o,d,(function(e,t){if(e)return n(e);n(null,t)}))}}function h(e,t,i,r,s){if(arguments.length<5)return u(i)(e,t,r);u(i,r)(e,t,s)}e(h,"factory",u);export{h as default,u as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index ae6782f..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '0id2h', 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( '0id30', '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( '0id3b', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0id43', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '0idBO', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0id43', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\n* @param {Collection} collection - input collection\n* @param {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","logger","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly","main"],"mappings":";;u2BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUR,EAAKK,SAGnDF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASR,EAAKS,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASP,GAkBzC,0WC/CIU,uDAAQC,CAAQ,4BAkBpB,SAASH,EAAOI,EAAYC,EAAKd,EAAMe,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMP,EAAWU,OACjBZ,EAAO,wBAAyBS,GAEnB,IAARA,EAEJ,OADAT,EAAO,qCACAK,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAEZE,EAAO,wBAAyBQ,GAChCR,EAAO,0BAA2BI,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdf,EAAO,kBAAmBkB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,GAPC,CAQD,CA5BDjB,EAAO,6BADPU,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJf,EAAO,2BAA4Be,EAAMM,SAClChB,EAAMU,KAGdf,EAAO,0CADPM,GAAS,EACgDG,GACpDC,EAAM,EACHG,IAEHP,IAAUG,GACdT,EAAO,qCACAK,EAAM,KAAMF,SAFpB,EAIA,CACF,CCxCA,SAASmB,EAAShC,EAASc,GAC1B,IAAIf,EACAkC,EACAC,EAGJ,GADAnC,EAAO,CAAA,EACFoC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMnC,EAAUC,EAAMC,GAErB,MAAMiC,EAEPC,EAAIpB,CACN,MACEoB,EAAIlC,EAEL,IAAMoC,EAAYF,GACjB,MAAM,IAAI5B,UAAWC,EAAQ,QAAS2B,IAUvC,YARqB,IAAhBnC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ6B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIN,UAAWC,EAAQ,QAASK,IAEvC,IAAMwB,EAAYrB,GACjB,MAAM,IAAIT,UAAWC,EAAQ,QAASQ,IAEvC,OAAOP,EAAOI,EAAY2B,EAASxC,EAAMmC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,EACZ,GACD,CACF,CC1EA,SAASyB,EAAkB1B,EAAY2B,EAASvC,EAASc,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAShC,EAATgC,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAShC,EAASc,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,EAC/C,CCnBA0B,EAAAC,EAAA,UAAAV"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index e34c2ba..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 79ee6fdf8996d12b39144c3f188ea11bf55cd8b0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Jan 2023 13:23:51 +0000 Subject: [PATCH 037/147] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 791 ---- .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 184 - .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 47 +- benchmark/benchmark.factory.js | 73 - benchmark/benchmark.js | 160 - branches.md | 53 - docs/repl.txt | 224 -- docs/types/test.ts | 166 - examples/index.js | 55 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 165 - lib/index.js | 77 - lib/limit.js | 142 - lib/main.js | 96 - lib/validate.js | 80 - package.json | 64 +- stats.html | 4044 +++++++++++++++++++++ test/test.factory.js | 1095 ------ test/test.js | 38 - test/test.main.js | 1035 ------ test/test.validate.js | 181 - 44 files changed, 4075 insertions(+), 6668 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/limit.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 6fc3d57..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-01-01T01:12:44.532Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1e08946..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 663f5df..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 45a5053..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '37 1 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4eea88..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,791 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -447,7 +446,7 @@ reduceRightAsync( files, acc, read, done ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -515,11 +514,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right +[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right/tree/esm -[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce +[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/tree/esm diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 46d8b83..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var reduceRightAsync; - var arr; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - reduceRightAsync = factory( onItem ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - var acc; - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 6ad0714..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var reduceRightAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=false', function benchmark( b ) { - var opts; - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'series': false - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var arr; - var len; - var acc; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'limit': 3 - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 2aded98..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right" -click B href "https://github.com/stdlib-js/utils-async-reduce-right/tree/main" -click C href "https://github.com/stdlib-js/utils-async-reduce-right/tree/production" -click D href "https://github.com/stdlib-js/utils-async-reduce-right/tree/esm" -click E href "https://github.com/stdlib-js/utils-async-reduce-right/tree/deno" -click F href "https://github.com/stdlib-js/utils-async-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right -[production-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3f22669..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,224 +0,0 @@ - -{{alias}}( collection, initial, [options,] reducer, done ) - Applies a function against an accumulator and each element in a collection - and returns the accumulated result, iterating from right to left. - - When invoked, `reducer` is provided a maximum of five arguments: - - - `accumulator`: accumulated value - - `value`: collection value - - `index`: collection index - - `collection`: the input collection - - `next`: a callback to be invoked after processing a collection `value` - - The actual number of provided arguments depends on function length. If - `reducer` accepts three arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `next` - - If `reducer` accepts four arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `index` - - `next` - - For every other `reducer` signature, `reducer` is provided all five - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `accumulator`: accumulated value - - If a provided function calls the `next` callback with a truthy `error` - argument, the function suspends execution and immediately calls the `done` - callback for subsequent `error` handling. - - Execution is *not* guaranteed to be asynchronous. To guarantee asynchrony, - 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`). - - The function does not support dynamic collection resizing. - - If provided an empty collection, the function invokes the `done` callback - with the `initial` value as the second argument. - - The function does not skip `undefined` elements. - - When processing collection elements concurrently, *beware* of race - conditions when updating an accumulator. This is especially true when an - accumulator is a primitive (e.g., a number). In general, prefer object - accumulators. - - Parameters - ---------- - collection: Array|TypedArray|Object - Input collection over which to iterate. If provided an object, the - object must be array-like (excluding strings and functions). - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - reducer: Function - The function to invoke for each element in a collection. - - done: Function - A callback invoked either upon processing all collection elements or - upon encountering an error. - - Examples - -------- - // Basic usage: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, fcn, done ) - 3000 - 2500 - 1000 - 6500 - - // Limit number of concurrent invocations: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'limit': 2 }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 2500 - 3000 - 1000 - 6500 - - // Process concurrently: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'series': false }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 1000 - 2500 - 3000 - 6500 - - -{{alias}}.factory( [options,] fcn ) - Returns a function which applies a function against an accumulator and each - element in a collection and returns the accumulated result, iterating from - right to left. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - fcn: Function - The function to invoke for each element in a collection. - - Returns - ------- - out: Function - A function which invokes a function for each element in a collection. - - Examples - -------- - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > var opts = { 'series': false }; - > var f = {{alias}}.factory( opts, fcn ); - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > f( arr, acc, done ) - 1000 - 2500 - 3000 - 6500 - > acc = { 'sum': 0 }; - > arr = [ 1000, 1500, 2000 ]; - > f( arr, acc, done ) - 1000 - 1500 - 2000 - 4500 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 143a132..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,166 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unsafe-any */ - -import reduceRightAsync = require( './index' ); - -const reducer = ( acc: any, value: number, index: number, next: Function ) => { - acc.sum += value; - if ( index === void 0 ) { - throw new Error( '`index` is missing.' ); - } - next( null, acc ); -}; - -const done = ( error: Error | null, acc: any ) => { - if ( error ) { - throw error; - } - if ( acc === void 0 ) { - throw new Error( '`acc` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( 2, acc, reducer, done ); // $ExpectError - reduceRightAsync( false, acc, reducer, done ); // $ExpectError - reduceRightAsync( true, acc, reducer, done ); // $ExpectError - reduceRightAsync( {}, acc, reducer, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a predicate argument which is not a predicate function... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 2, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, false, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, true, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 'abc', done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, [], done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a done callback argument which is not a function having a supported signature... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 2 ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, false ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, true ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 'abc' ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, {} ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, [] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const acc = { 'sum': 0 }; - reduceRightAsync(); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, reducer, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - reduceRightAsync.factory( reducer ); // $ExpectType FactoryFunction - reduceRightAsync.factory( { 'series': true }, reducer ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - reduceRightAsync.factory( [], reducer ); // $ExpectError - reduceRightAsync.factory( 123, reducer ); // $ExpectError - reduceRightAsync.factory( 'abc', reducer ); // $ExpectError - reduceRightAsync.factory( false, reducer ); // $ExpectError - reduceRightAsync.factory( true, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not a predicate function... -{ - reduceRightAsync.factory( {} ); // $ExpectError - reduceRightAsync.factory( true ); // $ExpectError - reduceRightAsync.factory( false ); // $ExpectError - reduceRightAsync.factory( {}, 123 ); // $ExpectError - reduceRightAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1( 12, acc, done ); // $ExpectError - fcn1( true, acc, done ); // $ExpectError - fcn1( false, acc, done ); // $ExpectError - fcn1( {}, acc, done ); // $ExpectError - - fcn1( [ 3000, 2500, 1000 ], acc, 12 ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, true ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, false ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, '5' ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, {} ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, [] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1(); // $ExpectError - fcn1( [ 3000, 2500, 1000 ] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - reduceRightAsync.factory( { 'limit': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': true }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': false }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - reduceRightAsync.factory( { 'series': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': 12 }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - reduceRightAsync.factory(); // $ExpectError - reduceRightAsync.factory( {}, reducer, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index dd64345..0000000 --- a/examples/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var resolve = require( 'path' ).resolve; -var readFile = require( '@stdlib/fs-read-file' ); -var reduceRightAsync = require( './../lib' ); - -var files = [ - resolve( __dirname, '..', 'package.json' ), - resolve( __dirname, '..', 'README.md' ) -]; - -function done( error, acc ) { - if ( error ) { - throw error; - } - console.log( acc.count ); -} - -function read( acc, file, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( file, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( null, acc ); - } - acc.count += 1; - next( null, acc ); - } -} - -var acc = { - 'count': 0 -}; -reduceRightAsync( files, acc, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index b19e443..9dc0658 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { Collection } from '@stdlib/types/object'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..4a5edf4 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.8-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";function m(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("0id30","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!d(e.limit))?new TypeError(r("0id3b","limit",e.limit)):null):new TypeError(r("0id2h",t))}function c(e){var t=e.default;if("function"==typeof t){var i=function(){return t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var f=c(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function p(e,t,i,r,s){var n,o,l,d,m,c;if(d=e.length,f("Collection length: %d",d),0===d)return f("Finished processing a collection."),s(null,t);for(l=d0&&p();function p(){function s(e,i){if(!o){if(e)return o=!0,u(e);f("Accumulator: %s",JSON.stringify(i)),t=i,u()}}f("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function u(e){return e?(f("Encountered an error: %s",e.message),s(e)):(f("Processed %d of %d collection elements.",n+=1,d),m>0?p():n===d?(f("Finished processing a collection."),s(null,t)):void 0)}}function u(e,n){var o,l,d;if(o={},arguments.length>1){if(l=m(o,e))throw l;d=n}else d=e;if(!t(d))throw new TypeError(r("0id43",d));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=s),c;function c(e,s,n){if(!i(e))throw new TypeError(r("0idBO",e));if(!t(n))throw new TypeError(r("0id43",n));return p(e,s,o,d,(function(e,t){if(e)return n(e);n(null,t)}))}}function h(e,t,i,r,s){if(arguments.length<5)return u(i)(e,t,r);u(i,r)(e,t,s)}e(h,"factory",u);export{h as default,u as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..ae6782f --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '0id2h', 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( '0id30', '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( '0id3b', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0id43', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '0idBO', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0id43', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\n* @param {Collection} collection - input collection\n* @param {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","logger","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly","main"],"mappings":";;u2BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUR,EAAKK,SAGnDF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASR,EAAKS,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASP,GAkBzC,0WC/CIU,uDAAQC,CAAQ,4BAkBpB,SAASH,EAAOI,EAAYC,EAAKd,EAAMe,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMP,EAAWU,OACjBZ,EAAO,wBAAyBS,GAEnB,IAARA,EAEJ,OADAT,EAAO,qCACAK,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAEZE,EAAO,wBAAyBQ,GAChCR,EAAO,0BAA2BI,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdf,EAAO,kBAAmBkB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,GAPC,CAQD,CA5BDjB,EAAO,6BADPU,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJf,EAAO,2BAA4Be,EAAMM,SAClChB,EAAMU,KAGdf,EAAO,0CADPM,GAAS,EACgDG,GACpDC,EAAM,EACHG,IAEHP,IAAUG,GACdT,EAAO,qCACAK,EAAM,KAAMF,SAFpB,EAIA,CACF,CCxCA,SAASmB,EAAShC,EAASc,GAC1B,IAAIf,EACAkC,EACAC,EAGJ,GADAnC,EAAO,CAAA,EACFoC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMnC,EAAUC,EAAMC,GAErB,MAAMiC,EAEPC,EAAIpB,CACN,MACEoB,EAAIlC,EAEL,IAAMoC,EAAYF,GACjB,MAAM,IAAI5B,UAAWC,EAAQ,QAAS2B,IAUvC,YARqB,IAAhBnC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ6B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIN,UAAWC,EAAQ,QAASK,IAEvC,IAAMwB,EAAYrB,GACjB,MAAM,IAAIT,UAAWC,EAAQ,QAASQ,IAEvC,OAAOP,EAAOI,EAAY2B,EAASxC,EAAMmC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,EACZ,GACD,CACF,CC1EA,SAASyB,EAAkB1B,EAAY2B,EAASvC,EAASc,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAShC,EAATgC,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAShC,EAASc,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,EAC/C,CCnBA0B,EAAAC,EAAA,UAAAV"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 6d67be2..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var validate = require( './validate.js' ); -var limit = require( './limit.js' ); - - -// MAIN // - -/** -* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} last argument must be a function -* @returns {Function} function which invokes the provided function once for each element in a collection -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error, data ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var opts = { -* 'series': false -* }; -* -* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: -* var reduceRightAsync = factory( opts, read ); -* -* // Create a collection over which to iterate: -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* // Define a callback which handles errors: -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* // Run `read` for each element in `files`: -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, done ); -*/ -function factory( options, fcn ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = fcn; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '0id43', f ) ); - } - if ( opts.series === void 0 && opts.limit === void 0 ) { - opts.series = true; - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return reduceRightAsync; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * @private - * @param {Collection} collection - input collection - * @param {*} initial - initial value - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be a collection - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function reduceRightAsync( collection, initial, done ) { - if ( !isCollection( collection ) ) { - throw new TypeError( format( '0idBO', collection ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '0id43', done ) ); - } - return limit( collection, initial, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {*} [acc] - accumulated value - * @returns {void} - */ - function clbk( error, acc ) { - if ( error ) { - return done( error ); - } - done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ae657ff..0000000 --- a/lib/index.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* @module @stdlib/utils-async-reduce-right -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' ); -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/limit.js b/lib/limit.js deleted file mode 100644 index cdb60af..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); - - -// VARIABLES // - -var debug = logger( 'reduce-right-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each element in a collection, limiting the number of concurrently pending functions and iterating from right to left. -* -* @private -* @param {Collection} collection - input collection -* @param {*} acc - initial value -* @param {Options} opts - function options -* @param {*} [opts.thisArg] - execution context -* @param {PositiveInteger} [opts.limit] - maximum number of pending function invocations -* @param {Function} fcn - function to invoke -* @param {Callback} done - function to invoke upon completion or upon encountering an error -* @returns {void} -*/ -function limit( collection, acc, opts, fcn, done ) { - var count; - var flg; - var lim; - var len; - var idx; - var i; - - len = collection.length; - debug( 'Collection length: %d', len ); - - if ( len === 0 ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - count = 0; - idx = len; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all collection elements... - if ( idx > 0 ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next element in a collection. - * - * @private - */ - function next() { - idx -= 1; - debug( 'Collection element %d: %s.', idx, JSON.stringify( collection[ idx ] ) ); - if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], cb ); - } else if ( fcn.length === 4 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, cb ); - } else { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len - } - /** - * Callback invoked once a provided function finishes processing a collection element. - * - * @private - * @param {*} [error] - error - * @param {*} [result] - accumulation result - * @returns {void} - */ - function cb( error, result ) { - if ( flg ) { - // Prevent further processing of collection elements: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Accumulator: %s', JSON.stringify( result ) ); - acc = result; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next collection element. - * - * @private - * @param {*} [error] - error - * @returns {void} - */ - function clbk( error ) { - if ( error ) { - debug( 'Encountered an error: %s', error.message ); - return done( error ); - } - count += 1; - debug( 'Processed %d of %d collection elements.', count, len ); - if ( idx > 0 ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 9f016bf..0000000 --- a/lib/main.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param {Collection} collection - input collection -* @param {*} initial - initial value -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} second-to-last argument must be a function -* @throws {TypeError} last argument must be a function -* @returns {void} -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -function reduceRightAsync( collection, initial, options, fcn, done ) { - if ( arguments.length < 5 ) { - return factory( options )( collection, initial, fcn ); - } - factory( options, fcn )( collection, initial, done ); -} - - -// EXPORTS // - -module.exports = reduceRightAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 6292663..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @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 -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'thisArg': {}, -* 'series': false, -* 'limit': 10 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '0id2h', options ) ); - } - if ( hasOwnProp( options, 'thisArg' ) ) { - opts.thisArg = options.thisArg; - } - if ( hasOwnProp( options, 'series' ) ) { - opts.series = options.series; - if ( !isBoolean( opts.series ) ) { - return new TypeError( format( '0id30', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '0id3b', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 6587773..55f16d9 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.8", "description": "Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,43 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-boolean": "^0.0.x", - "@stdlib/assert-is-collection": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/assert-is-positive-integer": "^0.0.x", - "@stdlib/constants-float64-pinf": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/constants-float64-eps": "^0.0.x", - "@stdlib/fs-read-file": "^0.0.x", - "@stdlib/utils-noop": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..d8f1bd2 --- /dev/null +++ b/stats.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 8244931..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1095 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( {}, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, next ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - factory( opts, next ); - }; - } -}); - -tape( 'the function returns a function (no options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided a collection (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a collection (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (1 argument)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (2 arguments)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with five arguments', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn() { - var value; - var next; - var acc; - var k; - - acc = arguments[ 0 ]; - value = arguments[ 1 ]; - k = arguments[ 2 ]; - next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( k, i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the returned function supports processing collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements concurrently', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 100, 250, 300 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements sequentially (limit = 1)', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of collection elements which are processed at any one time', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 250, 300, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 250, 100, 300 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var reduceRightAsync; - var arr; - - reduceRightAsync = factory( fcn ); - arr = []; - - reduceRightAsync( arr, 0, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var reduceRightAsync; - var obj; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = []; - obj = {}; - reduceRightAsync( arr, obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - i = 0; - - reduceRightAsync( arr, {}, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, acc ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the returned function does not skip empty elements', function test( t ) { - var reduceRightAsync; - var expected; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index f273a40..0000000 --- a/test/test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof reduceRightAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 1893240..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1035 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a collection', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (no options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, next, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, 0 ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - reduceRightAsync( [ 1, 2, 3 ], 0, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (1 argument)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (2 arguments)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with five arguments', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn() { - var next; - var acc; - var v; - - next = arguments[ 4 ]; - acc = arguments[ 0 ]; - v = arguments[ 1 ]; - - i -= 1; - j += 1; - - t.strictEqual( v, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, v ); - - function onTimeout() { - acc.sum += v; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'by default, the function processes collection elements sequentially', function test( t ) { - var values; - var count; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements concurrently', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 100, 250, 300 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': true - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially (limit = 1)', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var arr; - var ctx; - - arr = [ 3, 2, 1 ]; - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 3, 2, 1 ]; - opts = { - 'series': true - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 250, 100, 300 ]; - opts = { - 'limit': 2 - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var arr = []; - reduceRightAsync( arr, 0, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var arr = []; - var obj = {}; - - reduceRightAsync( arr, obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - arr = [ 3, 2, 1 ]; - i = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, value ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the function does not skip empty elements', function test( t ) { - var expected; - var arr; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, fcn, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 7660838..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,181 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `limit` option which is not a positive integer', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - -5, - 0, - 3.14, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'limit': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `series` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'series': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function accepts any value for the `thisArg` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'thisArg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err, null, 'returns null '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'thisArg': {}, - 'series': false, - 'limit': 10 - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From 88295fc91e33d4aefe1b9edb2ac7b00e19332d5f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Feb 2023 03:49:23 +0000 Subject: [PATCH 038/147] Transform error messages --- lib/factory.js | 8 ++++---- lib/validate.js | 8 ++++---- package.json | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index a627d69..6d67be2 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -22,7 +22,7 @@ var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var PINF = require( '@stdlib/constants-float64-pinf' ); var validate = require( './validate.js' ); var limit = require( './limit.js' ); @@ -110,7 +110,7 @@ function factory( options, fcn ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '0id43', f ) ); } if ( opts.series === void 0 && opts.limit === void 0 ) { opts.series = true; @@ -135,10 +135,10 @@ function factory( options, fcn ) { */ function reduceRightAsync( collection, initial, done ) { if ( !isCollection( collection ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a collection. Value: `%s`.', collection ) ); + throw new TypeError( format( '0idBO', collection ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '0id43', done ) ); } return limit( collection, initial, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index 9ba927e..6292663 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,7 +54,7 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0id2h', options ) ); } if ( hasOwnProp( options, 'thisArg' ) ) { opts.thisArg = options.thisArg; @@ -62,13 +62,13 @@ function validate( opts, options ) { if ( hasOwnProp( options, 'series' ) ) { opts.series = options.series; if ( !isBoolean( opts.series ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'series', opts.series ) ); + return new TypeError( format( '0id30', 'series', opts.series ) ); } } if ( hasOwnProp( options, 'limit' ) ) { opts.limit = options.limit; if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'limit', opts.limit ) ); + return new TypeError( format( '0id3b', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index ff5f76c..6587773 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-plain-object": "^0.0.x", "@stdlib/assert-is-positive-integer": "^0.0.x", "@stdlib/constants-float64-pinf": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x", "debug": "^2.6.9" From de9469d259a74f45d0ee739c73e981eb6133ef4b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Feb 2023 09:11:00 +0000 Subject: [PATCH 039/147] Remove files --- index.d.ts | 415 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4464 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 9dc0658..0000000 --- a/index.d.ts +++ /dev/null @@ -1,415 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Collection } from '@stdlib/types/object'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * The maximum number of pending invocations at any one time. - */ - limit?: number; - - /** - * Boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection (default: true). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback function. -*/ -type Nullary = () => void; - -/** -* Callback function. -* -* @param error - encountered error or null -*/ -type Unary = ( error: Error | null ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Binary = ( error: Error | null, accumulator: any ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param next - a callback to be invoked after processing a collection `value` -*/ -type TernaryReducer = ( accumulator: any, value: any, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuaternaryReducer = ( accumulator: any, value: any, index: number, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuinaryReducer = ( accumulator: any, value: any, index: number, collection: Collection, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type Reducer = TernaryReducer | QuaternaryReducer | QuinaryReducer; - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result. -* -* @param collection - input collection -* @param initial - initial value -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( collection: Collection, initial: any, done: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Interface for `reduceRightAsync`. -*/ -interface ReduceRightAsync { - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, {}, read, done ); - */ - ( collection: Collection, initial: any, options: Options, reducer: Reducer, done: Callback ): void; // tslint-disable-line max-line-length - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, read, done ); - */ - ( collection: Collection, initial: any, reducer: Reducer, done: Callback ): void; // tslint-disable-line max-line-length - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @throws must provide valid options - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var opts = { - * 'series': false - * }; - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( opts, read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( options: Options, reducer: Reducer ): FactoryFunction; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param reducer - function to invoke for each element in a collection - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( reducer: Reducer ): FactoryFunction; -} - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param collection - input collection -* @param initial - initial value -* @param options - function options -* @param options.thisArg - execution context -* @param options.limit - maximum number of pending invocations at any one time -* @param 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 (default: true) -* @param reducer - function to invoke for each element in a collection -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( `@stdlib/fs/read-file` ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -declare var reduceRightAsync: ReduceRightAsync; - - -// EXPORTS // - -export = reduceRightAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 4a5edf4..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.8-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";function m(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("0id30","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!d(e.limit))?new TypeError(r("0id3b","limit",e.limit)):null):new TypeError(r("0id2h",t))}function c(e){var t=e.default;if("function"==typeof t){var i=function(){return t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var f=c(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function p(e,t,i,r,s){var n,o,l,d,m,c;if(d=e.length,f("Collection length: %d",d),0===d)return f("Finished processing a collection."),s(null,t);for(l=d0&&p();function p(){function s(e,i){if(!o){if(e)return o=!0,u(e);f("Accumulator: %s",JSON.stringify(i)),t=i,u()}}f("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function u(e){return e?(f("Encountered an error: %s",e.message),s(e)):(f("Processed %d of %d collection elements.",n+=1,d),m>0?p():n===d?(f("Finished processing a collection."),s(null,t)):void 0)}}function u(e,n){var o,l,d;if(o={},arguments.length>1){if(l=m(o,e))throw l;d=n}else d=e;if(!t(d))throw new TypeError(r("0id43",d));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=s),c;function c(e,s,n){if(!i(e))throw new TypeError(r("0idBO",e));if(!t(n))throw new TypeError(r("0id43",n));return p(e,s,o,d,(function(e,t){if(e)return n(e);n(null,t)}))}}function h(e,t,i,r,s){if(arguments.length<5)return u(i)(e,t,r);u(i,r)(e,t,s)}e(h,"factory",u);export{h as default,u as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index ae6782f..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '0id2h', 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( '0id30', '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( '0id3b', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0id43', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '0idBO', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0id43', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\n* @param {Collection} collection - input collection\n* @param {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","logger","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly","main"],"mappings":";;u2BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUR,EAAKK,SAGnDF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASR,EAAKS,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASP,GAkBzC,0WC/CIU,uDAAQC,CAAQ,4BAkBpB,SAASH,EAAOI,EAAYC,EAAKd,EAAMe,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMP,EAAWU,OACjBZ,EAAO,wBAAyBS,GAEnB,IAARA,EAEJ,OADAT,EAAO,qCACAK,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAEZE,EAAO,wBAAyBQ,GAChCR,EAAO,0BAA2BI,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdf,EAAO,kBAAmBkB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,GAPC,CAQD,CA5BDjB,EAAO,6BADPU,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJf,EAAO,2BAA4Be,EAAMM,SAClChB,EAAMU,KAGdf,EAAO,0CADPM,GAAS,EACgDG,GACpDC,EAAM,EACHG,IAEHP,IAAUG,GACdT,EAAO,qCACAK,EAAM,KAAMF,SAFpB,EAIA,CACF,CCxCA,SAASmB,EAAShC,EAASc,GAC1B,IAAIf,EACAkC,EACAC,EAGJ,GADAnC,EAAO,CAAA,EACFoC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMnC,EAAUC,EAAMC,GAErB,MAAMiC,EAEPC,EAAIpB,CACN,MACEoB,EAAIlC,EAEL,IAAMoC,EAAYF,GACjB,MAAM,IAAI5B,UAAWC,EAAQ,QAAS2B,IAUvC,YARqB,IAAhBnC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ6B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIN,UAAWC,EAAQ,QAASK,IAEvC,IAAMwB,EAAYrB,GACjB,MAAM,IAAIT,UAAWC,EAAQ,QAASQ,IAEvC,OAAOP,EAAOI,EAAY2B,EAASxC,EAAMmC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,EACZ,GACD,CACF,CC1EA,SAASyB,EAAkB1B,EAAY2B,EAASvC,EAASc,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAShC,EAATgC,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAShC,EAASc,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,EAC/C,CCnBA0B,EAAAC,EAAA,UAAAV"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index d8f1bd2..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From b62053f930f317c344edf22f9deed4f64eb0341d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Feb 2023 09:11:35 +0000 Subject: [PATCH 040/147] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 791 --- .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 184 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 47 +- benchmark/benchmark.factory.js | 73 - benchmark/benchmark.js | 160 - branches.md | 53 - docs/repl.txt | 224 - docs/types/test.ts | 166 - examples/index.js | 55 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 165 - lib/index.js | 77 - lib/limit.js | 142 - lib/main.js | 96 - lib/validate.js | 80 - package.json | 64 +- stats.html | 6177 +++++++++++++++++++++ test/test.factory.js | 1095 ---- test/test.js | 38 - test/test.main.js | 1035 ---- test/test.validate.js | 181 - 44 files changed, 6208 insertions(+), 6668 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/limit.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index f12c822..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-02-01T01:35:40.795Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1e08946..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 663f5df..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 45a5053..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '37 1 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4eea88..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,791 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -447,7 +446,7 @@ reduceRightAsync( files, acc, read, done ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -515,11 +514,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right +[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right/tree/esm -[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce +[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/tree/esm diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 46d8b83..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var reduceRightAsync; - var arr; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - reduceRightAsync = factory( onItem ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - var acc; - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 6ad0714..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var reduceRightAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=false', function benchmark( b ) { - var opts; - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'series': false - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var arr; - var len; - var acc; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'limit': 3 - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 2aded98..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right" -click B href "https://github.com/stdlib-js/utils-async-reduce-right/tree/main" -click C href "https://github.com/stdlib-js/utils-async-reduce-right/tree/production" -click D href "https://github.com/stdlib-js/utils-async-reduce-right/tree/esm" -click E href "https://github.com/stdlib-js/utils-async-reduce-right/tree/deno" -click F href "https://github.com/stdlib-js/utils-async-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right -[production-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3f22669..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,224 +0,0 @@ - -{{alias}}( collection, initial, [options,] reducer, done ) - Applies a function against an accumulator and each element in a collection - and returns the accumulated result, iterating from right to left. - - When invoked, `reducer` is provided a maximum of five arguments: - - - `accumulator`: accumulated value - - `value`: collection value - - `index`: collection index - - `collection`: the input collection - - `next`: a callback to be invoked after processing a collection `value` - - The actual number of provided arguments depends on function length. If - `reducer` accepts three arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `next` - - If `reducer` accepts four arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `index` - - `next` - - For every other `reducer` signature, `reducer` is provided all five - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `accumulator`: accumulated value - - If a provided function calls the `next` callback with a truthy `error` - argument, the function suspends execution and immediately calls the `done` - callback for subsequent `error` handling. - - Execution is *not* guaranteed to be asynchronous. To guarantee asynchrony, - 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`). - - The function does not support dynamic collection resizing. - - If provided an empty collection, the function invokes the `done` callback - with the `initial` value as the second argument. - - The function does not skip `undefined` elements. - - When processing collection elements concurrently, *beware* of race - conditions when updating an accumulator. This is especially true when an - accumulator is a primitive (e.g., a number). In general, prefer object - accumulators. - - Parameters - ---------- - collection: Array|TypedArray|Object - Input collection over which to iterate. If provided an object, the - object must be array-like (excluding strings and functions). - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - reducer: Function - The function to invoke for each element in a collection. - - done: Function - A callback invoked either upon processing all collection elements or - upon encountering an error. - - Examples - -------- - // Basic usage: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, fcn, done ) - 3000 - 2500 - 1000 - 6500 - - // Limit number of concurrent invocations: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'limit': 2 }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 2500 - 3000 - 1000 - 6500 - - // Process concurrently: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'series': false }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 1000 - 2500 - 3000 - 6500 - - -{{alias}}.factory( [options,] fcn ) - Returns a function which applies a function against an accumulator and each - element in a collection and returns the accumulated result, iterating from - right to left. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - fcn: Function - The function to invoke for each element in a collection. - - Returns - ------- - out: Function - A function which invokes a function for each element in a collection. - - Examples - -------- - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > var opts = { 'series': false }; - > var f = {{alias}}.factory( opts, fcn ); - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > f( arr, acc, done ) - 1000 - 2500 - 3000 - 6500 - > acc = { 'sum': 0 }; - > arr = [ 1000, 1500, 2000 ]; - > f( arr, acc, done ) - 1000 - 1500 - 2000 - 4500 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 143a132..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,166 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unsafe-any */ - -import reduceRightAsync = require( './index' ); - -const reducer = ( acc: any, value: number, index: number, next: Function ) => { - acc.sum += value; - if ( index === void 0 ) { - throw new Error( '`index` is missing.' ); - } - next( null, acc ); -}; - -const done = ( error: Error | null, acc: any ) => { - if ( error ) { - throw error; - } - if ( acc === void 0 ) { - throw new Error( '`acc` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( 2, acc, reducer, done ); // $ExpectError - reduceRightAsync( false, acc, reducer, done ); // $ExpectError - reduceRightAsync( true, acc, reducer, done ); // $ExpectError - reduceRightAsync( {}, acc, reducer, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a predicate argument which is not a predicate function... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 2, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, false, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, true, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 'abc', done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, [], done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a done callback argument which is not a function having a supported signature... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 2 ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, false ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, true ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 'abc' ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, {} ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, [] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const acc = { 'sum': 0 }; - reduceRightAsync(); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, reducer, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - reduceRightAsync.factory( reducer ); // $ExpectType FactoryFunction - reduceRightAsync.factory( { 'series': true }, reducer ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - reduceRightAsync.factory( [], reducer ); // $ExpectError - reduceRightAsync.factory( 123, reducer ); // $ExpectError - reduceRightAsync.factory( 'abc', reducer ); // $ExpectError - reduceRightAsync.factory( false, reducer ); // $ExpectError - reduceRightAsync.factory( true, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not a predicate function... -{ - reduceRightAsync.factory( {} ); // $ExpectError - reduceRightAsync.factory( true ); // $ExpectError - reduceRightAsync.factory( false ); // $ExpectError - reduceRightAsync.factory( {}, 123 ); // $ExpectError - reduceRightAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1( 12, acc, done ); // $ExpectError - fcn1( true, acc, done ); // $ExpectError - fcn1( false, acc, done ); // $ExpectError - fcn1( {}, acc, done ); // $ExpectError - - fcn1( [ 3000, 2500, 1000 ], acc, 12 ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, true ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, false ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, '5' ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, {} ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, [] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1(); // $ExpectError - fcn1( [ 3000, 2500, 1000 ] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - reduceRightAsync.factory( { 'limit': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': true }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': false }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - reduceRightAsync.factory( { 'series': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': 12 }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - reduceRightAsync.factory(); // $ExpectError - reduceRightAsync.factory( {}, reducer, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index dd64345..0000000 --- a/examples/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var resolve = require( 'path' ).resolve; -var readFile = require( '@stdlib/fs-read-file' ); -var reduceRightAsync = require( './../lib' ); - -var files = [ - resolve( __dirname, '..', 'package.json' ), - resolve( __dirname, '..', 'README.md' ) -]; - -function done( error, acc ) { - if ( error ) { - throw error; - } - console.log( acc.count ); -} - -function read( acc, file, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( file, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( null, acc ); - } - acc.count += 1; - next( null, acc ); - } -} - -var acc = { - 'count': 0 -}; -reduceRightAsync( files, acc, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index b19e443..9dc0658 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { Collection } from '@stdlib/types/object'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..2270aa3 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.8-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";function m(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("0id30","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!d(e.limit))?new TypeError(r("0id3b","limit",e.limit)):null):new TypeError(r("0id2h",t))}function c(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){if(this instanceof e){var i=[null];i.push.apply(i,arguments);var r=Function.bind.apply(t,i);return new r}return t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var f=c(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function p(e,t,i,r,s){var n,o,l,d,m,c;if(d=e.length,f("Collection length: %d",d),0===d)return f("Finished processing a collection."),s(null,t);for(l=d0&&p();function p(){function s(e,i){if(!o){if(e)return o=!0,u(e);f("Accumulator: %s",JSON.stringify(i)),t=i,u()}}f("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function u(e){return e?(f("Encountered an error: %s",e.message),s(e)):(f("Processed %d of %d collection elements.",n+=1,d),m>0?p():n===d?(f("Finished processing a collection."),s(null,t)):void 0)}}function u(e,n){var o,l,d;if(o={},arguments.length>1){if(l=m(o,e))throw l;d=n}else d=e;if(!t(d))throw new TypeError(r("0id43",d));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=s),c;function c(e,s,n){if(!i(e))throw new TypeError(r("0idBO",e));if(!t(n))throw new TypeError(r("0id43",n));return p(e,s,o,d,(function(e,t){if(e)return n(e);n(null,t)}))}}function a(e,t,i,r,s){if(arguments.length<5)return u(i)(e,t,r);u(i,r)(e,t,s)}e(a,"factory",u);export{a as default,u as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..63e894f --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '0id2h', 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( '0id30', '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( '0id3b', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0id43', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '0idBO', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0id43', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\n* @param {Collection} collection - input collection\n* @param {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","logger","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly","main"],"mappings":";;u2BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUR,EAAKK,SAGnDF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASR,EAAKS,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASP,GAkBzC,8eC/CIU,uDAAQC,CAAQ,4BAkBpB,SAASH,EAAOI,EAAYC,EAAKd,EAAMe,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMP,EAAWU,OACjBZ,EAAO,wBAAyBS,GAEnB,IAARA,EAEJ,OADAT,EAAO,qCACAK,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAEZE,EAAO,wBAAyBQ,GAChCR,EAAO,0BAA2BI,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdf,EAAO,kBAAmBkB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,GAPC,CAQD,CA5BDjB,EAAO,6BADPU,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJf,EAAO,2BAA4Be,EAAMM,SAClChB,EAAMU,KAGdf,EAAO,0CADPM,GAAS,EACgDG,GACpDC,EAAM,EACHG,IAEHP,IAAUG,GACdT,EAAO,qCACAK,EAAM,KAAMF,SAFpB,EAIA,CACF,CCxCA,SAASmB,EAAShC,EAASc,GAC1B,IAAIf,EACAkC,EACAC,EAGJ,GADAnC,EAAO,CAAA,EACFoC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMnC,EAAUC,EAAMC,GAErB,MAAMiC,EAEPC,EAAIpB,CACN,MACEoB,EAAIlC,EAEL,IAAMoC,EAAYF,GACjB,MAAM,IAAI5B,UAAWC,EAAQ,QAAS2B,IAUvC,YARqB,IAAhBnC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ6B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIN,UAAWC,EAAQ,QAASK,IAEvC,IAAMwB,EAAYrB,GACjB,MAAM,IAAIT,UAAWC,EAAQ,QAASQ,IAEvC,OAAOP,EAAOI,EAAY2B,EAASxC,EAAMmC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,EACZ,GACD,CACF,CC1EA,SAASyB,EAAkB1B,EAAY2B,EAASvC,EAASc,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAShC,EAATgC,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAShC,EAASc,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,EAC/C,CCnBA0B,EAAAC,EAAA,UAAAV"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 6d67be2..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var validate = require( './validate.js' ); -var limit = require( './limit.js' ); - - -// MAIN // - -/** -* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} last argument must be a function -* @returns {Function} function which invokes the provided function once for each element in a collection -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error, data ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var opts = { -* 'series': false -* }; -* -* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: -* var reduceRightAsync = factory( opts, read ); -* -* // Create a collection over which to iterate: -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* // Define a callback which handles errors: -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* // Run `read` for each element in `files`: -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, done ); -*/ -function factory( options, fcn ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = fcn; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '0id43', f ) ); - } - if ( opts.series === void 0 && opts.limit === void 0 ) { - opts.series = true; - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return reduceRightAsync; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * @private - * @param {Collection} collection - input collection - * @param {*} initial - initial value - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be a collection - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function reduceRightAsync( collection, initial, done ) { - if ( !isCollection( collection ) ) { - throw new TypeError( format( '0idBO', collection ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '0id43', done ) ); - } - return limit( collection, initial, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {*} [acc] - accumulated value - * @returns {void} - */ - function clbk( error, acc ) { - if ( error ) { - return done( error ); - } - done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ae657ff..0000000 --- a/lib/index.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* @module @stdlib/utils-async-reduce-right -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' ); -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/limit.js b/lib/limit.js deleted file mode 100644 index cdb60af..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); - - -// VARIABLES // - -var debug = logger( 'reduce-right-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each element in a collection, limiting the number of concurrently pending functions and iterating from right to left. -* -* @private -* @param {Collection} collection - input collection -* @param {*} acc - initial value -* @param {Options} opts - function options -* @param {*} [opts.thisArg] - execution context -* @param {PositiveInteger} [opts.limit] - maximum number of pending function invocations -* @param {Function} fcn - function to invoke -* @param {Callback} done - function to invoke upon completion or upon encountering an error -* @returns {void} -*/ -function limit( collection, acc, opts, fcn, done ) { - var count; - var flg; - var lim; - var len; - var idx; - var i; - - len = collection.length; - debug( 'Collection length: %d', len ); - - if ( len === 0 ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - count = 0; - idx = len; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all collection elements... - if ( idx > 0 ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next element in a collection. - * - * @private - */ - function next() { - idx -= 1; - debug( 'Collection element %d: %s.', idx, JSON.stringify( collection[ idx ] ) ); - if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], cb ); - } else if ( fcn.length === 4 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, cb ); - } else { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len - } - /** - * Callback invoked once a provided function finishes processing a collection element. - * - * @private - * @param {*} [error] - error - * @param {*} [result] - accumulation result - * @returns {void} - */ - function cb( error, result ) { - if ( flg ) { - // Prevent further processing of collection elements: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Accumulator: %s', JSON.stringify( result ) ); - acc = result; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next collection element. - * - * @private - * @param {*} [error] - error - * @returns {void} - */ - function clbk( error ) { - if ( error ) { - debug( 'Encountered an error: %s', error.message ); - return done( error ); - } - count += 1; - debug( 'Processed %d of %d collection elements.', count, len ); - if ( idx > 0 ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 9f016bf..0000000 --- a/lib/main.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param {Collection} collection - input collection -* @param {*} initial - initial value -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} second-to-last argument must be a function -* @throws {TypeError} last argument must be a function -* @returns {void} -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -function reduceRightAsync( collection, initial, options, fcn, done ) { - if ( arguments.length < 5 ) { - return factory( options )( collection, initial, fcn ); - } - factory( options, fcn )( collection, initial, done ); -} - - -// EXPORTS // - -module.exports = reduceRightAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 6292663..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @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 -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'thisArg': {}, -* 'series': false, -* 'limit': 10 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '0id2h', options ) ); - } - if ( hasOwnProp( options, 'thisArg' ) ) { - opts.thisArg = options.thisArg; - } - if ( hasOwnProp( options, 'series' ) ) { - opts.series = options.series; - if ( !isBoolean( opts.series ) ) { - return new TypeError( format( '0id30', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '0id3b', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 6587773..55f16d9 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.8", "description": "Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,43 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-boolean": "^0.0.x", - "@stdlib/assert-is-collection": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/assert-is-positive-integer": "^0.0.x", - "@stdlib/constants-float64-pinf": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/constants-float64-eps": "^0.0.x", - "@stdlib/fs-read-file": "^0.0.x", - "@stdlib/utils-noop": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..9acb919 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 8244931..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1095 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( {}, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, next ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - factory( opts, next ); - }; - } -}); - -tape( 'the function returns a function (no options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided a collection (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a collection (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (1 argument)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (2 arguments)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with five arguments', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn() { - var value; - var next; - var acc; - var k; - - acc = arguments[ 0 ]; - value = arguments[ 1 ]; - k = arguments[ 2 ]; - next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( k, i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the returned function supports processing collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements concurrently', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 100, 250, 300 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements sequentially (limit = 1)', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of collection elements which are processed at any one time', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 250, 300, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 250, 100, 300 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var reduceRightAsync; - var arr; - - reduceRightAsync = factory( fcn ); - arr = []; - - reduceRightAsync( arr, 0, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var reduceRightAsync; - var obj; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = []; - obj = {}; - reduceRightAsync( arr, obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - i = 0; - - reduceRightAsync( arr, {}, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, acc ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the returned function does not skip empty elements', function test( t ) { - var reduceRightAsync; - var expected; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index f273a40..0000000 --- a/test/test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof reduceRightAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 1893240..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1035 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a collection', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (no options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, next, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, 0 ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - reduceRightAsync( [ 1, 2, 3 ], 0, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (1 argument)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (2 arguments)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with five arguments', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn() { - var next; - var acc; - var v; - - next = arguments[ 4 ]; - acc = arguments[ 0 ]; - v = arguments[ 1 ]; - - i -= 1; - j += 1; - - t.strictEqual( v, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, v ); - - function onTimeout() { - acc.sum += v; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'by default, the function processes collection elements sequentially', function test( t ) { - var values; - var count; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements concurrently', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 100, 250, 300 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': true - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially (limit = 1)', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var arr; - var ctx; - - arr = [ 3, 2, 1 ]; - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 3, 2, 1 ]; - opts = { - 'series': true - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 250, 100, 300 ]; - opts = { - 'limit': 2 - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var arr = []; - reduceRightAsync( arr, 0, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var arr = []; - var obj = {}; - - reduceRightAsync( arr, obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - arr = [ 3, 2, 1 ]; - i = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, value ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the function does not skip empty elements', function test( t ) { - var expected; - var arr; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, fcn, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 7660838..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,181 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `limit` option which is not a positive integer', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - -5, - 0, - 3.14, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'limit': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `series` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'series': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function accepts any value for the `thisArg` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'thisArg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err, null, 'returns null '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'thisArg': {}, - 'series': false, - 'limit': 10 - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From e781cf7a6fff9732b31fea72618d242d88578a19 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Mar 2023 05:57:36 +0000 Subject: [PATCH 041/147] Transform error messages --- lib/factory.js | 8 ++++---- lib/validate.js | 8 ++++---- package.json | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index a627d69..6d67be2 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -22,7 +22,7 @@ var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var PINF = require( '@stdlib/constants-float64-pinf' ); var validate = require( './validate.js' ); var limit = require( './limit.js' ); @@ -110,7 +110,7 @@ function factory( options, fcn ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '0id43', f ) ); } if ( opts.series === void 0 && opts.limit === void 0 ) { opts.series = true; @@ -135,10 +135,10 @@ function factory( options, fcn ) { */ function reduceRightAsync( collection, initial, done ) { if ( !isCollection( collection ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a collection. Value: `%s`.', collection ) ); + throw new TypeError( format( '0idBO', collection ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '0id43', done ) ); } return limit( collection, initial, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index 9ba927e..6292663 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,7 +54,7 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0id2h', options ) ); } if ( hasOwnProp( options, 'thisArg' ) ) { opts.thisArg = options.thisArg; @@ -62,13 +62,13 @@ function validate( opts, options ) { if ( hasOwnProp( options, 'series' ) ) { opts.series = options.series; if ( !isBoolean( opts.series ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'series', opts.series ) ); + return new TypeError( format( '0id30', 'series', opts.series ) ); } } if ( hasOwnProp( options, 'limit' ) ) { opts.limit = options.limit; if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'limit', opts.limit ) ); + return new TypeError( format( '0id3b', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index e0057f8..8660367 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-plain-object": "^0.0.7", "@stdlib/assert-is-positive-integer": "^0.0.7", "@stdlib/constants-float64-pinf": "^0.0.8", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/types": "^0.0.14", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7", "debug": "^2.6.9" From 7373007bdd21c75ee5d112371f6fbe93331e4e9e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Mar 2023 14:32:03 +0000 Subject: [PATCH 042/147] Remove files --- index.d.ts | 415 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6597 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 9dc0658..0000000 --- a/index.d.ts +++ /dev/null @@ -1,415 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Collection } from '@stdlib/types/object'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * The maximum number of pending invocations at any one time. - */ - limit?: number; - - /** - * Boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection (default: true). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback function. -*/ -type Nullary = () => void; - -/** -* Callback function. -* -* @param error - encountered error or null -*/ -type Unary = ( error: Error | null ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Binary = ( error: Error | null, accumulator: any ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param next - a callback to be invoked after processing a collection `value` -*/ -type TernaryReducer = ( accumulator: any, value: any, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuaternaryReducer = ( accumulator: any, value: any, index: number, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuinaryReducer = ( accumulator: any, value: any, index: number, collection: Collection, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type Reducer = TernaryReducer | QuaternaryReducer | QuinaryReducer; - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result. -* -* @param collection - input collection -* @param initial - initial value -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( collection: Collection, initial: any, done: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Interface for `reduceRightAsync`. -*/ -interface ReduceRightAsync { - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, {}, read, done ); - */ - ( collection: Collection, initial: any, options: Options, reducer: Reducer, done: Callback ): void; // tslint-disable-line max-line-length - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, read, done ); - */ - ( collection: Collection, initial: any, reducer: Reducer, done: Callback ): void; // tslint-disable-line max-line-length - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @throws must provide valid options - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var opts = { - * 'series': false - * }; - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( opts, read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( options: Options, reducer: Reducer ): FactoryFunction; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param reducer - function to invoke for each element in a collection - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( reducer: Reducer ): FactoryFunction; -} - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param collection - input collection -* @param initial - initial value -* @param options - function options -* @param options.thisArg - execution context -* @param options.limit - maximum number of pending invocations at any one time -* @param 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 (default: true) -* @param reducer - function to invoke for each element in a collection -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( `@stdlib/fs/read-file` ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -declare var reduceRightAsync: ReduceRightAsync; - - -// EXPORTS // - -export = reduceRightAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 2270aa3..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.8-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";function m(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("0id30","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!d(e.limit))?new TypeError(r("0id3b","limit",e.limit)):null):new TypeError(r("0id2h",t))}function c(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){if(this instanceof e){var i=[null];i.push.apply(i,arguments);var r=Function.bind.apply(t,i);return new r}return t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var f=c(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function p(e,t,i,r,s){var n,o,l,d,m,c;if(d=e.length,f("Collection length: %d",d),0===d)return f("Finished processing a collection."),s(null,t);for(l=d0&&p();function p(){function s(e,i){if(!o){if(e)return o=!0,u(e);f("Accumulator: %s",JSON.stringify(i)),t=i,u()}}f("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function u(e){return e?(f("Encountered an error: %s",e.message),s(e)):(f("Processed %d of %d collection elements.",n+=1,d),m>0?p():n===d?(f("Finished processing a collection."),s(null,t)):void 0)}}function u(e,n){var o,l,d;if(o={},arguments.length>1){if(l=m(o,e))throw l;d=n}else d=e;if(!t(d))throw new TypeError(r("0id43",d));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=s),c;function c(e,s,n){if(!i(e))throw new TypeError(r("0idBO",e));if(!t(n))throw new TypeError(r("0id43",n));return p(e,s,o,d,(function(e,t){if(e)return n(e);n(null,t)}))}}function a(e,t,i,r,s){if(arguments.length<5)return u(i)(e,t,r);u(i,r)(e,t,s)}e(a,"factory",u);export{a as default,u as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 63e894f..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '0id2h', 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( '0id30', '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( '0id3b', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0id43', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '0idBO', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0id43', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\n* @param {Collection} collection - input collection\n* @param {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","logger","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly","main"],"mappings":";;u2BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUR,EAAKK,SAGnDF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASR,EAAKS,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASP,GAkBzC,8eC/CIU,uDAAQC,CAAQ,4BAkBpB,SAASH,EAAOI,EAAYC,EAAKd,EAAMe,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMP,EAAWU,OACjBZ,EAAO,wBAAyBS,GAEnB,IAARA,EAEJ,OADAT,EAAO,qCACAK,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAEZE,EAAO,wBAAyBQ,GAChCR,EAAO,0BAA2BI,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdf,EAAO,kBAAmBkB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,GAPC,CAQD,CA5BDjB,EAAO,6BADPU,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJf,EAAO,2BAA4Be,EAAMM,SAClChB,EAAMU,KAGdf,EAAO,0CADPM,GAAS,EACgDG,GACpDC,EAAM,EACHG,IAEHP,IAAUG,GACdT,EAAO,qCACAK,EAAM,KAAMF,SAFpB,EAIA,CACF,CCxCA,SAASmB,EAAShC,EAASc,GAC1B,IAAIf,EACAkC,EACAC,EAGJ,GADAnC,EAAO,CAAA,EACFoC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMnC,EAAUC,EAAMC,GAErB,MAAMiC,EAEPC,EAAIpB,CACN,MACEoB,EAAIlC,EAEL,IAAMoC,EAAYF,GACjB,MAAM,IAAI5B,UAAWC,EAAQ,QAAS2B,IAUvC,YARqB,IAAhBnC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ6B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIN,UAAWC,EAAQ,QAASK,IAEvC,IAAMwB,EAAYrB,GACjB,MAAM,IAAIT,UAAWC,EAAQ,QAASQ,IAEvC,OAAOP,EAAOI,EAAY2B,EAASxC,EAAMmC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,EACZ,GACD,CACF,CC1EA,SAASyB,EAAkB1B,EAAY2B,EAASvC,EAASc,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAShC,EAATgC,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAShC,EAASc,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,EAC/C,CCnBA0B,EAAAC,EAAA,UAAAV"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 9acb919..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 48d683540e5670f214c149e23ece8fd0959ae21a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Mar 2023 14:32:47 +0000 Subject: [PATCH 043/147] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 798 --- .github/workflows/publish.yml | 236 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 47 +- benchmark/benchmark.factory.js | 73 - benchmark/benchmark.js | 160 - branches.md | 53 - docs/repl.txt | 224 - docs/types/test.ts | 166 - examples/index.js | 55 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 165 - lib/index.js | 77 - lib/limit.js | 142 - lib/main.js | 96 - lib/validate.js | 80 - package.json | 64 +- stats.html | 6177 +++++++++++++++++++++ test/test.factory.js | 1095 ---- test/test.js | 38 - test/test.main.js | 1035 ---- test/test.validate.js | 181 - 44 files changed, 6208 insertions(+), 6803 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/limit.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 3cadeff..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-03-01T03:52:07.920Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1e08946..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 663f5df..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 45a5053..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '37 1 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 3e8e2db..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,798 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -447,7 +446,7 @@ reduceRightAsync( files, acc, read, done ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -515,11 +514,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right +[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right/tree/esm -[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce +[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/tree/esm diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 46d8b83..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var reduceRightAsync; - var arr; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - reduceRightAsync = factory( onItem ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - var acc; - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 6ad0714..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var reduceRightAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=false', function benchmark( b ) { - var opts; - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'series': false - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var arr; - var len; - var acc; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'limit': 3 - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index acfc6d6..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right" -%% click B href "https://github.com/stdlib-js/utils-async-reduce-right/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-reduce-right/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-reduce-right/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-reduce-right/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right -[production-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3f22669..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,224 +0,0 @@ - -{{alias}}( collection, initial, [options,] reducer, done ) - Applies a function against an accumulator and each element in a collection - and returns the accumulated result, iterating from right to left. - - When invoked, `reducer` is provided a maximum of five arguments: - - - `accumulator`: accumulated value - - `value`: collection value - - `index`: collection index - - `collection`: the input collection - - `next`: a callback to be invoked after processing a collection `value` - - The actual number of provided arguments depends on function length. If - `reducer` accepts three arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `next` - - If `reducer` accepts four arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `index` - - `next` - - For every other `reducer` signature, `reducer` is provided all five - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `accumulator`: accumulated value - - If a provided function calls the `next` callback with a truthy `error` - argument, the function suspends execution and immediately calls the `done` - callback for subsequent `error` handling. - - Execution is *not* guaranteed to be asynchronous. To guarantee asynchrony, - 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`). - - The function does not support dynamic collection resizing. - - If provided an empty collection, the function invokes the `done` callback - with the `initial` value as the second argument. - - The function does not skip `undefined` elements. - - When processing collection elements concurrently, *beware* of race - conditions when updating an accumulator. This is especially true when an - accumulator is a primitive (e.g., a number). In general, prefer object - accumulators. - - Parameters - ---------- - collection: Array|TypedArray|Object - Input collection over which to iterate. If provided an object, the - object must be array-like (excluding strings and functions). - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - reducer: Function - The function to invoke for each element in a collection. - - done: Function - A callback invoked either upon processing all collection elements or - upon encountering an error. - - Examples - -------- - // Basic usage: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, fcn, done ) - 3000 - 2500 - 1000 - 6500 - - // Limit number of concurrent invocations: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'limit': 2 }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 2500 - 3000 - 1000 - 6500 - - // Process concurrently: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'series': false }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 1000 - 2500 - 3000 - 6500 - - -{{alias}}.factory( [options,] fcn ) - Returns a function which applies a function against an accumulator and each - element in a collection and returns the accumulated result, iterating from - right to left. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - fcn: Function - The function to invoke for each element in a collection. - - Returns - ------- - out: Function - A function which invokes a function for each element in a collection. - - Examples - -------- - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > var opts = { 'series': false }; - > var f = {{alias}}.factory( opts, fcn ); - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > f( arr, acc, done ) - 1000 - 2500 - 3000 - 6500 - > acc = { 'sum': 0 }; - > arr = [ 1000, 1500, 2000 ]; - > f( arr, acc, done ) - 1000 - 1500 - 2000 - 4500 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 143a132..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,166 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unsafe-any */ - -import reduceRightAsync = require( './index' ); - -const reducer = ( acc: any, value: number, index: number, next: Function ) => { - acc.sum += value; - if ( index === void 0 ) { - throw new Error( '`index` is missing.' ); - } - next( null, acc ); -}; - -const done = ( error: Error | null, acc: any ) => { - if ( error ) { - throw error; - } - if ( acc === void 0 ) { - throw new Error( '`acc` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( 2, acc, reducer, done ); // $ExpectError - reduceRightAsync( false, acc, reducer, done ); // $ExpectError - reduceRightAsync( true, acc, reducer, done ); // $ExpectError - reduceRightAsync( {}, acc, reducer, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a predicate argument which is not a predicate function... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 2, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, false, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, true, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 'abc', done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, [], done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a done callback argument which is not a function having a supported signature... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 2 ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, false ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, true ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 'abc' ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, {} ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, [] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const acc = { 'sum': 0 }; - reduceRightAsync(); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, reducer, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - reduceRightAsync.factory( reducer ); // $ExpectType FactoryFunction - reduceRightAsync.factory( { 'series': true }, reducer ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - reduceRightAsync.factory( [], reducer ); // $ExpectError - reduceRightAsync.factory( 123, reducer ); // $ExpectError - reduceRightAsync.factory( 'abc', reducer ); // $ExpectError - reduceRightAsync.factory( false, reducer ); // $ExpectError - reduceRightAsync.factory( true, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not a predicate function... -{ - reduceRightAsync.factory( {} ); // $ExpectError - reduceRightAsync.factory( true ); // $ExpectError - reduceRightAsync.factory( false ); // $ExpectError - reduceRightAsync.factory( {}, 123 ); // $ExpectError - reduceRightAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1( 12, acc, done ); // $ExpectError - fcn1( true, acc, done ); // $ExpectError - fcn1( false, acc, done ); // $ExpectError - fcn1( {}, acc, done ); // $ExpectError - - fcn1( [ 3000, 2500, 1000 ], acc, 12 ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, true ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, false ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, '5' ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, {} ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, [] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1(); // $ExpectError - fcn1( [ 3000, 2500, 1000 ] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - reduceRightAsync.factory( { 'limit': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': true }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': false }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - reduceRightAsync.factory( { 'series': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': 12 }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - reduceRightAsync.factory(); // $ExpectError - reduceRightAsync.factory( {}, reducer, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index dd64345..0000000 --- a/examples/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var resolve = require( 'path' ).resolve; -var readFile = require( '@stdlib/fs-read-file' ); -var reduceRightAsync = require( './../lib' ); - -var files = [ - resolve( __dirname, '..', 'package.json' ), - resolve( __dirname, '..', 'README.md' ) -]; - -function done( error, acc ) { - if ( error ) { - throw error; - } - console.log( acc.count ); -} - -function read( acc, file, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( file, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( null, acc ); - } - acc.count += 1; - next( null, acc ); - } -} - -var acc = { - 'count': 0 -}; -reduceRightAsync( files, acc, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index b19e443..9dc0658 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { Collection } from '@stdlib/types/object'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..2270aa3 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.8-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";function m(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("0id30","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!d(e.limit))?new TypeError(r("0id3b","limit",e.limit)):null):new TypeError(r("0id2h",t))}function c(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){if(this instanceof e){var i=[null];i.push.apply(i,arguments);var r=Function.bind.apply(t,i);return new r}return t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var f=c(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function p(e,t,i,r,s){var n,o,l,d,m,c;if(d=e.length,f("Collection length: %d",d),0===d)return f("Finished processing a collection."),s(null,t);for(l=d0&&p();function p(){function s(e,i){if(!o){if(e)return o=!0,u(e);f("Accumulator: %s",JSON.stringify(i)),t=i,u()}}f("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function u(e){return e?(f("Encountered an error: %s",e.message),s(e)):(f("Processed %d of %d collection elements.",n+=1,d),m>0?p():n===d?(f("Finished processing a collection."),s(null,t)):void 0)}}function u(e,n){var o,l,d;if(o={},arguments.length>1){if(l=m(o,e))throw l;d=n}else d=e;if(!t(d))throw new TypeError(r("0id43",d));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=s),c;function c(e,s,n){if(!i(e))throw new TypeError(r("0idBO",e));if(!t(n))throw new TypeError(r("0id43",n));return p(e,s,o,d,(function(e,t){if(e)return n(e);n(null,t)}))}}function a(e,t,i,r,s){if(arguments.length<5)return u(i)(e,t,r);u(i,r)(e,t,s)}e(a,"factory",u);export{a as default,u as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..63e894f --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '0id2h', 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( '0id30', '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( '0id3b', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0id43', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '0idBO', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0id43', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\n* @param {Collection} collection - input collection\n* @param {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","logger","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly","main"],"mappings":";;u2BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUR,EAAKK,SAGnDF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASR,EAAKS,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASP,GAkBzC,8eC/CIU,uDAAQC,CAAQ,4BAkBpB,SAASH,EAAOI,EAAYC,EAAKd,EAAMe,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMP,EAAWU,OACjBZ,EAAO,wBAAyBS,GAEnB,IAARA,EAEJ,OADAT,EAAO,qCACAK,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAEZE,EAAO,wBAAyBQ,GAChCR,EAAO,0BAA2BI,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdf,EAAO,kBAAmBkB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,GAPC,CAQD,CA5BDjB,EAAO,6BADPU,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJf,EAAO,2BAA4Be,EAAMM,SAClChB,EAAMU,KAGdf,EAAO,0CADPM,GAAS,EACgDG,GACpDC,EAAM,EACHG,IAEHP,IAAUG,GACdT,EAAO,qCACAK,EAAM,KAAMF,SAFpB,EAIA,CACF,CCxCA,SAASmB,EAAShC,EAASc,GAC1B,IAAIf,EACAkC,EACAC,EAGJ,GADAnC,EAAO,CAAA,EACFoC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMnC,EAAUC,EAAMC,GAErB,MAAMiC,EAEPC,EAAIpB,CACN,MACEoB,EAAIlC,EAEL,IAAMoC,EAAYF,GACjB,MAAM,IAAI5B,UAAWC,EAAQ,QAAS2B,IAUvC,YARqB,IAAhBnC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ6B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIN,UAAWC,EAAQ,QAASK,IAEvC,IAAMwB,EAAYrB,GACjB,MAAM,IAAIT,UAAWC,EAAQ,QAASQ,IAEvC,OAAOP,EAAOI,EAAY2B,EAASxC,EAAMmC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,EACZ,GACD,CACF,CC1EA,SAASyB,EAAkB1B,EAAY2B,EAASvC,EAASc,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAShC,EAATgC,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAShC,EAASc,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,EAC/C,CCnBA0B,EAAAC,EAAA,UAAAV"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 6d67be2..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var validate = require( './validate.js' ); -var limit = require( './limit.js' ); - - -// MAIN // - -/** -* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} last argument must be a function -* @returns {Function} function which invokes the provided function once for each element in a collection -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error, data ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var opts = { -* 'series': false -* }; -* -* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: -* var reduceRightAsync = factory( opts, read ); -* -* // Create a collection over which to iterate: -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* // Define a callback which handles errors: -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* // Run `read` for each element in `files`: -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, done ); -*/ -function factory( options, fcn ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = fcn; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '0id43', f ) ); - } - if ( opts.series === void 0 && opts.limit === void 0 ) { - opts.series = true; - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return reduceRightAsync; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * @private - * @param {Collection} collection - input collection - * @param {*} initial - initial value - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be a collection - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function reduceRightAsync( collection, initial, done ) { - if ( !isCollection( collection ) ) { - throw new TypeError( format( '0idBO', collection ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '0id43', done ) ); - } - return limit( collection, initial, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {*} [acc] - accumulated value - * @returns {void} - */ - function clbk( error, acc ) { - if ( error ) { - return done( error ); - } - done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ae657ff..0000000 --- a/lib/index.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* @module @stdlib/utils-async-reduce-right -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' ); -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/limit.js b/lib/limit.js deleted file mode 100644 index cdb60af..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); - - -// VARIABLES // - -var debug = logger( 'reduce-right-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each element in a collection, limiting the number of concurrently pending functions and iterating from right to left. -* -* @private -* @param {Collection} collection - input collection -* @param {*} acc - initial value -* @param {Options} opts - function options -* @param {*} [opts.thisArg] - execution context -* @param {PositiveInteger} [opts.limit] - maximum number of pending function invocations -* @param {Function} fcn - function to invoke -* @param {Callback} done - function to invoke upon completion or upon encountering an error -* @returns {void} -*/ -function limit( collection, acc, opts, fcn, done ) { - var count; - var flg; - var lim; - var len; - var idx; - var i; - - len = collection.length; - debug( 'Collection length: %d', len ); - - if ( len === 0 ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - count = 0; - idx = len; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all collection elements... - if ( idx > 0 ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next element in a collection. - * - * @private - */ - function next() { - idx -= 1; - debug( 'Collection element %d: %s.', idx, JSON.stringify( collection[ idx ] ) ); - if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], cb ); - } else if ( fcn.length === 4 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, cb ); - } else { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len - } - /** - * Callback invoked once a provided function finishes processing a collection element. - * - * @private - * @param {*} [error] - error - * @param {*} [result] - accumulation result - * @returns {void} - */ - function cb( error, result ) { - if ( flg ) { - // Prevent further processing of collection elements: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Accumulator: %s', JSON.stringify( result ) ); - acc = result; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next collection element. - * - * @private - * @param {*} [error] - error - * @returns {void} - */ - function clbk( error ) { - if ( error ) { - debug( 'Encountered an error: %s', error.message ); - return done( error ); - } - count += 1; - debug( 'Processed %d of %d collection elements.', count, len ); - if ( idx > 0 ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 9f016bf..0000000 --- a/lib/main.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param {Collection} collection - input collection -* @param {*} initial - initial value -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} second-to-last argument must be a function -* @throws {TypeError} last argument must be a function -* @returns {void} -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -function reduceRightAsync( collection, initial, options, fcn, done ) { - if ( arguments.length < 5 ) { - return factory( options )( collection, initial, fcn ); - } - factory( options, fcn )( collection, initial, done ); -} - - -// EXPORTS // - -module.exports = reduceRightAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 6292663..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @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 -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'thisArg': {}, -* 'series': false, -* 'limit': 10 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '0id2h', options ) ); - } - if ( hasOwnProp( options, 'thisArg' ) ) { - opts.thisArg = options.thisArg; - } - if ( hasOwnProp( options, 'series' ) ) { - opts.series = options.series; - if ( !isBoolean( opts.series ) ) { - return new TypeError( format( '0id30', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '0id3b', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 8660367..cfe057f 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.8", "description": "Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,43 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.0.7", - "@stdlib/assert-is-boolean": "^0.0.8", - "@stdlib/assert-is-collection": "^0.0.8", - "@stdlib/assert-is-function": "^0.0.8", - "@stdlib/assert-is-plain-object": "^0.0.7", - "@stdlib/assert-is-positive-integer": "^0.0.7", - "@stdlib/constants-float64-pinf": "^0.0.8", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/types": "^0.0.14", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.12", - "@stdlib/constants-float64-eps": "^0.0.8", - "@stdlib/fs-read-file": "^0.0.8", - "@stdlib/utils-noop": "^0.0.14", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..2370368 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 8244931..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1095 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( {}, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, next ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - factory( opts, next ); - }; - } -}); - -tape( 'the function returns a function (no options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided a collection (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a collection (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (1 argument)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (2 arguments)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with five arguments', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn() { - var value; - var next; - var acc; - var k; - - acc = arguments[ 0 ]; - value = arguments[ 1 ]; - k = arguments[ 2 ]; - next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( k, i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the returned function supports processing collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements concurrently', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 100, 250, 300 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements sequentially (limit = 1)', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of collection elements which are processed at any one time', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 250, 300, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 250, 100, 300 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var reduceRightAsync; - var arr; - - reduceRightAsync = factory( fcn ); - arr = []; - - reduceRightAsync( arr, 0, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var reduceRightAsync; - var obj; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = []; - obj = {}; - reduceRightAsync( arr, obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - i = 0; - - reduceRightAsync( arr, {}, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, acc ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the returned function does not skip empty elements', function test( t ) { - var reduceRightAsync; - var expected; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index f273a40..0000000 --- a/test/test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof reduceRightAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 1893240..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1035 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a collection', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (no options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, next, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, 0 ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - reduceRightAsync( [ 1, 2, 3 ], 0, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (1 argument)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (2 arguments)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with five arguments', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn() { - var next; - var acc; - var v; - - next = arguments[ 4 ]; - acc = arguments[ 0 ]; - v = arguments[ 1 ]; - - i -= 1; - j += 1; - - t.strictEqual( v, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, v ); - - function onTimeout() { - acc.sum += v; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'by default, the function processes collection elements sequentially', function test( t ) { - var values; - var count; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements concurrently', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 100, 250, 300 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': true - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially (limit = 1)', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var arr; - var ctx; - - arr = [ 3, 2, 1 ]; - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 3, 2, 1 ]; - opts = { - 'series': true - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 250, 100, 300 ]; - opts = { - 'limit': 2 - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var arr = []; - reduceRightAsync( arr, 0, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var arr = []; - var obj = {}; - - reduceRightAsync( arr, obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - arr = [ 3, 2, 1 ]; - i = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, value ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the function does not skip empty elements', function test( t ) { - var expected; - var arr; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, fcn, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 7660838..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,181 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `limit` option which is not a positive integer', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - -5, - 0, - 3.14, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'limit': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `series` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'series': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function accepts any value for the `thisArg` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'thisArg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err, null, 'returns null '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'thisArg': {}, - 'series': false, - 'limit': 10 - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From 37404acf29b6237a310e163b34e609c8b2179f9b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Apr 2023 06:33:29 +0000 Subject: [PATCH 044/147] Transform error messages --- lib/factory.js | 8 ++++---- lib/validate.js | 8 ++++---- package.json | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index a627d69..6d67be2 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -22,7 +22,7 @@ var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var PINF = require( '@stdlib/constants-float64-pinf' ); var validate = require( './validate.js' ); var limit = require( './limit.js' ); @@ -110,7 +110,7 @@ function factory( options, fcn ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '0id43', f ) ); } if ( opts.series === void 0 && opts.limit === void 0 ) { opts.series = true; @@ -135,10 +135,10 @@ function factory( options, fcn ) { */ function reduceRightAsync( collection, initial, done ) { if ( !isCollection( collection ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a collection. Value: `%s`.', collection ) ); + throw new TypeError( format( '0idBO', collection ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '0id43', done ) ); } return limit( collection, initial, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index 9ba927e..6292663 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,7 +54,7 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0id2h', options ) ); } if ( hasOwnProp( options, 'thisArg' ) ) { opts.thisArg = options.thisArg; @@ -62,13 +62,13 @@ function validate( opts, options ) { if ( hasOwnProp( options, 'series' ) ) { opts.series = options.series; if ( !isBoolean( opts.series ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'series', opts.series ) ); + return new TypeError( format( '0id30', 'series', opts.series ) ); } } if ( hasOwnProp( options, 'limit' ) ) { opts.limit = options.limit; if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'limit', opts.limit ) ); + return new TypeError( format( '0id3b', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index e0057f8..8660367 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-plain-object": "^0.0.7", "@stdlib/assert-is-positive-integer": "^0.0.7", "@stdlib/constants-float64-pinf": "^0.0.8", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/types": "^0.0.14", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7", "debug": "^2.6.9" From ec332baa185cdea546198b9ca25d580416230d6b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Apr 2023 13:34:33 +0000 Subject: [PATCH 045/147] Remove files --- index.d.ts | 415 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6597 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 9dc0658..0000000 --- a/index.d.ts +++ /dev/null @@ -1,415 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Collection } from '@stdlib/types/object'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * The maximum number of pending invocations at any one time. - */ - limit?: number; - - /** - * Boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection (default: true). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback function. -*/ -type Nullary = () => void; - -/** -* Callback function. -* -* @param error - encountered error or null -*/ -type Unary = ( error: Error | null ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Binary = ( error: Error | null, accumulator: any ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param next - a callback to be invoked after processing a collection `value` -*/ -type TernaryReducer = ( accumulator: any, value: any, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuaternaryReducer = ( accumulator: any, value: any, index: number, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuinaryReducer = ( accumulator: any, value: any, index: number, collection: Collection, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type Reducer = TernaryReducer | QuaternaryReducer | QuinaryReducer; - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result. -* -* @param collection - input collection -* @param initial - initial value -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( collection: Collection, initial: any, done: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Interface for `reduceRightAsync`. -*/ -interface ReduceRightAsync { - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, {}, read, done ); - */ - ( collection: Collection, initial: any, options: Options, reducer: Reducer, done: Callback ): void; // tslint-disable-line max-line-length - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, read, done ); - */ - ( collection: Collection, initial: any, reducer: Reducer, done: Callback ): void; // tslint-disable-line max-line-length - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @throws must provide valid options - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var opts = { - * 'series': false - * }; - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( opts, read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( options: Options, reducer: Reducer ): FactoryFunction; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param reducer - function to invoke for each element in a collection - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( reducer: Reducer ): FactoryFunction; -} - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param collection - input collection -* @param initial - initial value -* @param options - function options -* @param options.thisArg - execution context -* @param options.limit - maximum number of pending invocations at any one time -* @param 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 (default: true) -* @param reducer - function to invoke for each element in a collection -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( `@stdlib/fs/read-file` ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -declare var reduceRightAsync: ReduceRightAsync; - - -// EXPORTS // - -export = reduceRightAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 2270aa3..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.8-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";function m(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("0id30","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!d(e.limit))?new TypeError(r("0id3b","limit",e.limit)):null):new TypeError(r("0id2h",t))}function c(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){if(this instanceof e){var i=[null];i.push.apply(i,arguments);var r=Function.bind.apply(t,i);return new r}return t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var f=c(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function p(e,t,i,r,s){var n,o,l,d,m,c;if(d=e.length,f("Collection length: %d",d),0===d)return f("Finished processing a collection."),s(null,t);for(l=d0&&p();function p(){function s(e,i){if(!o){if(e)return o=!0,u(e);f("Accumulator: %s",JSON.stringify(i)),t=i,u()}}f("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function u(e){return e?(f("Encountered an error: %s",e.message),s(e)):(f("Processed %d of %d collection elements.",n+=1,d),m>0?p():n===d?(f("Finished processing a collection."),s(null,t)):void 0)}}function u(e,n){var o,l,d;if(o={},arguments.length>1){if(l=m(o,e))throw l;d=n}else d=e;if(!t(d))throw new TypeError(r("0id43",d));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=s),c;function c(e,s,n){if(!i(e))throw new TypeError(r("0idBO",e));if(!t(n))throw new TypeError(r("0id43",n));return p(e,s,o,d,(function(e,t){if(e)return n(e);n(null,t)}))}}function a(e,t,i,r,s){if(arguments.length<5)return u(i)(e,t,r);u(i,r)(e,t,s)}e(a,"factory",u);export{a as default,u as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 63e894f..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '0id2h', 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( '0id30', '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( '0id3b', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0id43', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '0idBO', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0id43', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\n* @param {Collection} collection - input collection\n* @param {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","logger","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly","main"],"mappings":";;u2BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUR,EAAKK,SAGnDF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASR,EAAKS,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASP,GAkBzC,8eC/CIU,uDAAQC,CAAQ,4BAkBpB,SAASH,EAAOI,EAAYC,EAAKd,EAAMe,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMP,EAAWU,OACjBZ,EAAO,wBAAyBS,GAEnB,IAARA,EAEJ,OADAT,EAAO,qCACAK,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAEZE,EAAO,wBAAyBQ,GAChCR,EAAO,0BAA2BI,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdf,EAAO,kBAAmBkB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,GAPC,CAQD,CA5BDjB,EAAO,6BADPU,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJf,EAAO,2BAA4Be,EAAMM,SAClChB,EAAMU,KAGdf,EAAO,0CADPM,GAAS,EACgDG,GACpDC,EAAM,EACHG,IAEHP,IAAUG,GACdT,EAAO,qCACAK,EAAM,KAAMF,SAFpB,EAIA,CACF,CCxCA,SAASmB,EAAShC,EAASc,GAC1B,IAAIf,EACAkC,EACAC,EAGJ,GADAnC,EAAO,CAAA,EACFoC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMnC,EAAUC,EAAMC,GAErB,MAAMiC,EAEPC,EAAIpB,CACN,MACEoB,EAAIlC,EAEL,IAAMoC,EAAYF,GACjB,MAAM,IAAI5B,UAAWC,EAAQ,QAAS2B,IAUvC,YARqB,IAAhBnC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ6B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIN,UAAWC,EAAQ,QAASK,IAEvC,IAAMwB,EAAYrB,GACjB,MAAM,IAAIT,UAAWC,EAAQ,QAASQ,IAEvC,OAAOP,EAAOI,EAAY2B,EAASxC,EAAMmC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,EACZ,GACD,CACF,CC1EA,SAASyB,EAAkB1B,EAAY2B,EAASvC,EAASc,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAShC,EAATgC,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAShC,EAASc,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,EAC/C,CCnBA0B,EAAAC,EAAA,UAAAV"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 2370368..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From f1df9349c7f6fce70c83116c3f20e5a4814e3a1a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Apr 2023 13:35:08 +0000 Subject: [PATCH 046/147] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 798 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 47 +- benchmark/benchmark.factory.js | 73 - benchmark/benchmark.js | 160 - branches.md | 53 - docs/repl.txt | 224 - docs/types/test.ts | 166 - examples/index.js | 55 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 165 - lib/index.js | 77 - lib/limit.js | 142 - lib/main.js | 96 - lib/validate.js | 80 - package.json | 64 +- stats.html | 6177 +++++++++++++++++++++ test/test.factory.js | 1095 ---- test/test.js | 38 - test/test.main.js | 1035 ---- test/test.validate.js | 181 - 44 files changed, 6208 insertions(+), 6809 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/limit.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 1021ffe..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-04-01T04:24:57.658Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1e08946..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 663f5df..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 45a5053..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '37 1 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 3e8e2db..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,798 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -447,7 +446,7 @@ reduceRightAsync( files, acc, read, done ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -515,11 +514,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right +[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right/tree/esm -[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce +[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/tree/esm diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 46d8b83..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var reduceRightAsync; - var arr; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - reduceRightAsync = factory( onItem ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - var acc; - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 6ad0714..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var reduceRightAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=false', function benchmark( b ) { - var opts; - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'series': false - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var arr; - var len; - var acc; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'limit': 3 - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index acfc6d6..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right" -%% click B href "https://github.com/stdlib-js/utils-async-reduce-right/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-reduce-right/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-reduce-right/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-reduce-right/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right -[production-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3f22669..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,224 +0,0 @@ - -{{alias}}( collection, initial, [options,] reducer, done ) - Applies a function against an accumulator and each element in a collection - and returns the accumulated result, iterating from right to left. - - When invoked, `reducer` is provided a maximum of five arguments: - - - `accumulator`: accumulated value - - `value`: collection value - - `index`: collection index - - `collection`: the input collection - - `next`: a callback to be invoked after processing a collection `value` - - The actual number of provided arguments depends on function length. If - `reducer` accepts three arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `next` - - If `reducer` accepts four arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `index` - - `next` - - For every other `reducer` signature, `reducer` is provided all five - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `accumulator`: accumulated value - - If a provided function calls the `next` callback with a truthy `error` - argument, the function suspends execution and immediately calls the `done` - callback for subsequent `error` handling. - - Execution is *not* guaranteed to be asynchronous. To guarantee asynchrony, - 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`). - - The function does not support dynamic collection resizing. - - If provided an empty collection, the function invokes the `done` callback - with the `initial` value as the second argument. - - The function does not skip `undefined` elements. - - When processing collection elements concurrently, *beware* of race - conditions when updating an accumulator. This is especially true when an - accumulator is a primitive (e.g., a number). In general, prefer object - accumulators. - - Parameters - ---------- - collection: Array|TypedArray|Object - Input collection over which to iterate. If provided an object, the - object must be array-like (excluding strings and functions). - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - reducer: Function - The function to invoke for each element in a collection. - - done: Function - A callback invoked either upon processing all collection elements or - upon encountering an error. - - Examples - -------- - // Basic usage: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, fcn, done ) - 3000 - 2500 - 1000 - 6500 - - // Limit number of concurrent invocations: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'limit': 2 }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 2500 - 3000 - 1000 - 6500 - - // Process concurrently: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'series': false }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 1000 - 2500 - 3000 - 6500 - - -{{alias}}.factory( [options,] fcn ) - Returns a function which applies a function against an accumulator and each - element in a collection and returns the accumulated result, iterating from - right to left. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - fcn: Function - The function to invoke for each element in a collection. - - Returns - ------- - out: Function - A function which invokes a function for each element in a collection. - - Examples - -------- - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > var opts = { 'series': false }; - > var f = {{alias}}.factory( opts, fcn ); - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > f( arr, acc, done ) - 1000 - 2500 - 3000 - 6500 - > acc = { 'sum': 0 }; - > arr = [ 1000, 1500, 2000 ]; - > f( arr, acc, done ) - 1000 - 1500 - 2000 - 4500 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 143a132..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,166 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unsafe-any */ - -import reduceRightAsync = require( './index' ); - -const reducer = ( acc: any, value: number, index: number, next: Function ) => { - acc.sum += value; - if ( index === void 0 ) { - throw new Error( '`index` is missing.' ); - } - next( null, acc ); -}; - -const done = ( error: Error | null, acc: any ) => { - if ( error ) { - throw error; - } - if ( acc === void 0 ) { - throw new Error( '`acc` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( 2, acc, reducer, done ); // $ExpectError - reduceRightAsync( false, acc, reducer, done ); // $ExpectError - reduceRightAsync( true, acc, reducer, done ); // $ExpectError - reduceRightAsync( {}, acc, reducer, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a predicate argument which is not a predicate function... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 2, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, false, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, true, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 'abc', done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, [], done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a done callback argument which is not a function having a supported signature... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 2 ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, false ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, true ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 'abc' ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, {} ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, [] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const acc = { 'sum': 0 }; - reduceRightAsync(); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, reducer, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - reduceRightAsync.factory( reducer ); // $ExpectType FactoryFunction - reduceRightAsync.factory( { 'series': true }, reducer ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - reduceRightAsync.factory( [], reducer ); // $ExpectError - reduceRightAsync.factory( 123, reducer ); // $ExpectError - reduceRightAsync.factory( 'abc', reducer ); // $ExpectError - reduceRightAsync.factory( false, reducer ); // $ExpectError - reduceRightAsync.factory( true, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not a predicate function... -{ - reduceRightAsync.factory( {} ); // $ExpectError - reduceRightAsync.factory( true ); // $ExpectError - reduceRightAsync.factory( false ); // $ExpectError - reduceRightAsync.factory( {}, 123 ); // $ExpectError - reduceRightAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1( 12, acc, done ); // $ExpectError - fcn1( true, acc, done ); // $ExpectError - fcn1( false, acc, done ); // $ExpectError - fcn1( {}, acc, done ); // $ExpectError - - fcn1( [ 3000, 2500, 1000 ], acc, 12 ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, true ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, false ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, '5' ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, {} ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, [] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1(); // $ExpectError - fcn1( [ 3000, 2500, 1000 ] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - reduceRightAsync.factory( { 'limit': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': true }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': false }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - reduceRightAsync.factory( { 'series': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': 12 }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - reduceRightAsync.factory(); // $ExpectError - reduceRightAsync.factory( {}, reducer, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index dd64345..0000000 --- a/examples/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var resolve = require( 'path' ).resolve; -var readFile = require( '@stdlib/fs-read-file' ); -var reduceRightAsync = require( './../lib' ); - -var files = [ - resolve( __dirname, '..', 'package.json' ), - resolve( __dirname, '..', 'README.md' ) -]; - -function done( error, acc ) { - if ( error ) { - throw error; - } - console.log( acc.count ); -} - -function read( acc, file, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( file, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( null, acc ); - } - acc.count += 1; - next( null, acc ); - } -} - -var acc = { - 'count': 0 -}; -reduceRightAsync( files, acc, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index b19e443..9dc0658 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { Collection } from '@stdlib/types/object'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..2270aa3 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.8-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";function m(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("0id30","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!d(e.limit))?new TypeError(r("0id3b","limit",e.limit)):null):new TypeError(r("0id2h",t))}function c(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){if(this instanceof e){var i=[null];i.push.apply(i,arguments);var r=Function.bind.apply(t,i);return new r}return t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var f=c(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function p(e,t,i,r,s){var n,o,l,d,m,c;if(d=e.length,f("Collection length: %d",d),0===d)return f("Finished processing a collection."),s(null,t);for(l=d0&&p();function p(){function s(e,i){if(!o){if(e)return o=!0,u(e);f("Accumulator: %s",JSON.stringify(i)),t=i,u()}}f("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function u(e){return e?(f("Encountered an error: %s",e.message),s(e)):(f("Processed %d of %d collection elements.",n+=1,d),m>0?p():n===d?(f("Finished processing a collection."),s(null,t)):void 0)}}function u(e,n){var o,l,d;if(o={},arguments.length>1){if(l=m(o,e))throw l;d=n}else d=e;if(!t(d))throw new TypeError(r("0id43",d));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=s),c;function c(e,s,n){if(!i(e))throw new TypeError(r("0idBO",e));if(!t(n))throw new TypeError(r("0id43",n));return p(e,s,o,d,(function(e,t){if(e)return n(e);n(null,t)}))}}function a(e,t,i,r,s){if(arguments.length<5)return u(i)(e,t,r);u(i,r)(e,t,s)}e(a,"factory",u);export{a as default,u as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..63e894f --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '0id2h', 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( '0id30', '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( '0id3b', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0id43', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '0idBO', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0id43', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\n* @param {Collection} collection - input collection\n* @param {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","logger","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly","main"],"mappings":";;u2BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUR,EAAKK,SAGnDF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASR,EAAKS,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASP,GAkBzC,8eC/CIU,uDAAQC,CAAQ,4BAkBpB,SAASH,EAAOI,EAAYC,EAAKd,EAAMe,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMP,EAAWU,OACjBZ,EAAO,wBAAyBS,GAEnB,IAARA,EAEJ,OADAT,EAAO,qCACAK,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAEZE,EAAO,wBAAyBQ,GAChCR,EAAO,0BAA2BI,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdf,EAAO,kBAAmBkB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,GAPC,CAQD,CA5BDjB,EAAO,6BADPU,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJf,EAAO,2BAA4Be,EAAMM,SAClChB,EAAMU,KAGdf,EAAO,0CADPM,GAAS,EACgDG,GACpDC,EAAM,EACHG,IAEHP,IAAUG,GACdT,EAAO,qCACAK,EAAM,KAAMF,SAFpB,EAIA,CACF,CCxCA,SAASmB,EAAShC,EAASc,GAC1B,IAAIf,EACAkC,EACAC,EAGJ,GADAnC,EAAO,CAAA,EACFoC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMnC,EAAUC,EAAMC,GAErB,MAAMiC,EAEPC,EAAIpB,CACN,MACEoB,EAAIlC,EAEL,IAAMoC,EAAYF,GACjB,MAAM,IAAI5B,UAAWC,EAAQ,QAAS2B,IAUvC,YARqB,IAAhBnC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ6B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIN,UAAWC,EAAQ,QAASK,IAEvC,IAAMwB,EAAYrB,GACjB,MAAM,IAAIT,UAAWC,EAAQ,QAASQ,IAEvC,OAAOP,EAAOI,EAAY2B,EAASxC,EAAMmC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,EACZ,GACD,CACF,CC1EA,SAASyB,EAAkB1B,EAAY2B,EAASvC,EAASc,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAShC,EAATgC,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAShC,EAASc,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,EAC/C,CCnBA0B,EAAAC,EAAA,UAAAV"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 6d67be2..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var validate = require( './validate.js' ); -var limit = require( './limit.js' ); - - -// MAIN // - -/** -* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} last argument must be a function -* @returns {Function} function which invokes the provided function once for each element in a collection -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error, data ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var opts = { -* 'series': false -* }; -* -* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: -* var reduceRightAsync = factory( opts, read ); -* -* // Create a collection over which to iterate: -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* // Define a callback which handles errors: -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* // Run `read` for each element in `files`: -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, done ); -*/ -function factory( options, fcn ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = fcn; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '0id43', f ) ); - } - if ( opts.series === void 0 && opts.limit === void 0 ) { - opts.series = true; - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return reduceRightAsync; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * @private - * @param {Collection} collection - input collection - * @param {*} initial - initial value - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be a collection - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function reduceRightAsync( collection, initial, done ) { - if ( !isCollection( collection ) ) { - throw new TypeError( format( '0idBO', collection ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '0id43', done ) ); - } - return limit( collection, initial, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {*} [acc] - accumulated value - * @returns {void} - */ - function clbk( error, acc ) { - if ( error ) { - return done( error ); - } - done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ae657ff..0000000 --- a/lib/index.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* @module @stdlib/utils-async-reduce-right -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' ); -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/limit.js b/lib/limit.js deleted file mode 100644 index cdb60af..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); - - -// VARIABLES // - -var debug = logger( 'reduce-right-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each element in a collection, limiting the number of concurrently pending functions and iterating from right to left. -* -* @private -* @param {Collection} collection - input collection -* @param {*} acc - initial value -* @param {Options} opts - function options -* @param {*} [opts.thisArg] - execution context -* @param {PositiveInteger} [opts.limit] - maximum number of pending function invocations -* @param {Function} fcn - function to invoke -* @param {Callback} done - function to invoke upon completion or upon encountering an error -* @returns {void} -*/ -function limit( collection, acc, opts, fcn, done ) { - var count; - var flg; - var lim; - var len; - var idx; - var i; - - len = collection.length; - debug( 'Collection length: %d', len ); - - if ( len === 0 ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - count = 0; - idx = len; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all collection elements... - if ( idx > 0 ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next element in a collection. - * - * @private - */ - function next() { - idx -= 1; - debug( 'Collection element %d: %s.', idx, JSON.stringify( collection[ idx ] ) ); - if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], cb ); - } else if ( fcn.length === 4 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, cb ); - } else { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len - } - /** - * Callback invoked once a provided function finishes processing a collection element. - * - * @private - * @param {*} [error] - error - * @param {*} [result] - accumulation result - * @returns {void} - */ - function cb( error, result ) { - if ( flg ) { - // Prevent further processing of collection elements: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Accumulator: %s', JSON.stringify( result ) ); - acc = result; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next collection element. - * - * @private - * @param {*} [error] - error - * @returns {void} - */ - function clbk( error ) { - if ( error ) { - debug( 'Encountered an error: %s', error.message ); - return done( error ); - } - count += 1; - debug( 'Processed %d of %d collection elements.', count, len ); - if ( idx > 0 ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 9f016bf..0000000 --- a/lib/main.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param {Collection} collection - input collection -* @param {*} initial - initial value -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} second-to-last argument must be a function -* @throws {TypeError} last argument must be a function -* @returns {void} -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -function reduceRightAsync( collection, initial, options, fcn, done ) { - if ( arguments.length < 5 ) { - return factory( options )( collection, initial, fcn ); - } - factory( options, fcn )( collection, initial, done ); -} - - -// EXPORTS // - -module.exports = reduceRightAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 6292663..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @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 -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'thisArg': {}, -* 'series': false, -* 'limit': 10 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '0id2h', options ) ); - } - if ( hasOwnProp( options, 'thisArg' ) ) { - opts.thisArg = options.thisArg; - } - if ( hasOwnProp( options, 'series' ) ) { - opts.series = options.series; - if ( !isBoolean( opts.series ) ) { - return new TypeError( format( '0id30', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '0id3b', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 8660367..cfe057f 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.8", "description": "Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,43 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.0.7", - "@stdlib/assert-is-boolean": "^0.0.8", - "@stdlib/assert-is-collection": "^0.0.8", - "@stdlib/assert-is-function": "^0.0.8", - "@stdlib/assert-is-plain-object": "^0.0.7", - "@stdlib/assert-is-positive-integer": "^0.0.7", - "@stdlib/constants-float64-pinf": "^0.0.8", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/types": "^0.0.14", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.12", - "@stdlib/constants-float64-eps": "^0.0.8", - "@stdlib/fs-read-file": "^0.0.8", - "@stdlib/utils-noop": "^0.0.14", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..377bba2 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 8244931..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1095 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( {}, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, next ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - factory( opts, next ); - }; - } -}); - -tape( 'the function returns a function (no options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided a collection (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a collection (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (1 argument)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (2 arguments)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with five arguments', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn() { - var value; - var next; - var acc; - var k; - - acc = arguments[ 0 ]; - value = arguments[ 1 ]; - k = arguments[ 2 ]; - next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( k, i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the returned function supports processing collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements concurrently', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 100, 250, 300 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements sequentially (limit = 1)', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of collection elements which are processed at any one time', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 250, 300, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 250, 100, 300 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var reduceRightAsync; - var arr; - - reduceRightAsync = factory( fcn ); - arr = []; - - reduceRightAsync( arr, 0, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var reduceRightAsync; - var obj; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = []; - obj = {}; - reduceRightAsync( arr, obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - i = 0; - - reduceRightAsync( arr, {}, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, acc ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the returned function does not skip empty elements', function test( t ) { - var reduceRightAsync; - var expected; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index f273a40..0000000 --- a/test/test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof reduceRightAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 1893240..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1035 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a collection', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (no options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, next, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, 0 ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - reduceRightAsync( [ 1, 2, 3 ], 0, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (1 argument)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (2 arguments)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with five arguments', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn() { - var next; - var acc; - var v; - - next = arguments[ 4 ]; - acc = arguments[ 0 ]; - v = arguments[ 1 ]; - - i -= 1; - j += 1; - - t.strictEqual( v, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, v ); - - function onTimeout() { - acc.sum += v; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'by default, the function processes collection elements sequentially', function test( t ) { - var values; - var count; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements concurrently', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 100, 250, 300 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': true - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially (limit = 1)', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var arr; - var ctx; - - arr = [ 3, 2, 1 ]; - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 3, 2, 1 ]; - opts = { - 'series': true - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 250, 100, 300 ]; - opts = { - 'limit': 2 - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var arr = []; - reduceRightAsync( arr, 0, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var arr = []; - var obj = {}; - - reduceRightAsync( arr, obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - arr = [ 3, 2, 1 ]; - i = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, value ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the function does not skip empty elements', function test( t ) { - var expected; - var arr; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, fcn, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 7660838..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,181 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `limit` option which is not a positive integer', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - -5, - 0, - 3.14, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'limit': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `series` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'series': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function accepts any value for the `thisArg` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'thisArg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err, null, 'returns null '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'thisArg': {}, - 'series': false, - 'limit': 10 - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From b5511e35f8519a8a41d757b4741897b89d92ce2e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 May 2023 06:18:26 +0000 Subject: [PATCH 047/147] Transform error messages --- lib/factory.js | 8 ++++---- lib/validate.js | 8 ++++---- package.json | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index a627d69..6d67be2 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -22,7 +22,7 @@ var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var PINF = require( '@stdlib/constants-float64-pinf' ); var validate = require( './validate.js' ); var limit = require( './limit.js' ); @@ -110,7 +110,7 @@ function factory( options, fcn ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '0id43', f ) ); } if ( opts.series === void 0 && opts.limit === void 0 ) { opts.series = true; @@ -135,10 +135,10 @@ function factory( options, fcn ) { */ function reduceRightAsync( collection, initial, done ) { if ( !isCollection( collection ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a collection. Value: `%s`.', collection ) ); + throw new TypeError( format( '0idBO', collection ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '0id43', done ) ); } return limit( collection, initial, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index 9ba927e..6292663 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,7 +54,7 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0id2h', options ) ); } if ( hasOwnProp( options, 'thisArg' ) ) { opts.thisArg = options.thisArg; @@ -62,13 +62,13 @@ function validate( opts, options ) { if ( hasOwnProp( options, 'series' ) ) { opts.series = options.series; if ( !isBoolean( opts.series ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'series', opts.series ) ); + return new TypeError( format( '0id30', 'series', opts.series ) ); } } if ( hasOwnProp( options, 'limit' ) ) { opts.limit = options.limit; if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'limit', opts.limit ) ); + return new TypeError( format( '0id3b', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index e0057f8..8660367 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-plain-object": "^0.0.7", "@stdlib/assert-is-positive-integer": "^0.0.7", "@stdlib/constants-float64-pinf": "^0.0.8", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/types": "^0.0.14", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7", "debug": "^2.6.9" From 356b39952c6c249652498a37546bbc03878fa091 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 May 2023 13:10:38 +0000 Subject: [PATCH 048/147] Remove files --- index.d.ts | 415 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6597 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 9dc0658..0000000 --- a/index.d.ts +++ /dev/null @@ -1,415 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Collection } from '@stdlib/types/object'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * The maximum number of pending invocations at any one time. - */ - limit?: number; - - /** - * Boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection (default: true). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback function. -*/ -type Nullary = () => void; - -/** -* Callback function. -* -* @param error - encountered error or null -*/ -type Unary = ( error: Error | null ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Binary = ( error: Error | null, accumulator: any ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param next - a callback to be invoked after processing a collection `value` -*/ -type TernaryReducer = ( accumulator: any, value: any, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuaternaryReducer = ( accumulator: any, value: any, index: number, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuinaryReducer = ( accumulator: any, value: any, index: number, collection: Collection, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type Reducer = TernaryReducer | QuaternaryReducer | QuinaryReducer; - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result. -* -* @param collection - input collection -* @param initial - initial value -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( collection: Collection, initial: any, done: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Interface for `reduceRightAsync`. -*/ -interface ReduceRightAsync { - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, {}, read, done ); - */ - ( collection: Collection, initial: any, options: Options, reducer: Reducer, done: Callback ): void; // tslint-disable-line max-line-length - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, read, done ); - */ - ( collection: Collection, initial: any, reducer: Reducer, done: Callback ): void; // tslint-disable-line max-line-length - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @throws must provide valid options - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var opts = { - * 'series': false - * }; - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( opts, read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( options: Options, reducer: Reducer ): FactoryFunction; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param reducer - function to invoke for each element in a collection - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( reducer: Reducer ): FactoryFunction; -} - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param collection - input collection -* @param initial - initial value -* @param options - function options -* @param options.thisArg - execution context -* @param options.limit - maximum number of pending invocations at any one time -* @param 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 (default: true) -* @param reducer - function to invoke for each element in a collection -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( `@stdlib/fs/read-file` ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -declare var reduceRightAsync: ReduceRightAsync; - - -// EXPORTS // - -export = reduceRightAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 2270aa3..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.8-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";function m(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("0id30","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!d(e.limit))?new TypeError(r("0id3b","limit",e.limit)):null):new TypeError(r("0id2h",t))}function c(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){if(this instanceof e){var i=[null];i.push.apply(i,arguments);var r=Function.bind.apply(t,i);return new r}return t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var f=c(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function p(e,t,i,r,s){var n,o,l,d,m,c;if(d=e.length,f("Collection length: %d",d),0===d)return f("Finished processing a collection."),s(null,t);for(l=d0&&p();function p(){function s(e,i){if(!o){if(e)return o=!0,u(e);f("Accumulator: %s",JSON.stringify(i)),t=i,u()}}f("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function u(e){return e?(f("Encountered an error: %s",e.message),s(e)):(f("Processed %d of %d collection elements.",n+=1,d),m>0?p():n===d?(f("Finished processing a collection."),s(null,t)):void 0)}}function u(e,n){var o,l,d;if(o={},arguments.length>1){if(l=m(o,e))throw l;d=n}else d=e;if(!t(d))throw new TypeError(r("0id43",d));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=s),c;function c(e,s,n){if(!i(e))throw new TypeError(r("0idBO",e));if(!t(n))throw new TypeError(r("0id43",n));return p(e,s,o,d,(function(e,t){if(e)return n(e);n(null,t)}))}}function a(e,t,i,r,s){if(arguments.length<5)return u(i)(e,t,r);u(i,r)(e,t,s)}e(a,"factory",u);export{a as default,u as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 63e894f..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '0id2h', 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( '0id30', '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( '0id3b', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0id43', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '0idBO', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0id43', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\n* @param {Collection} collection - input collection\n* @param {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","logger","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly","main"],"mappings":";;u2BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUR,EAAKK,SAGnDF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASR,EAAKS,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASP,GAkBzC,8eC/CIU,uDAAQC,CAAQ,4BAkBpB,SAASH,EAAOI,EAAYC,EAAKd,EAAMe,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMP,EAAWU,OACjBZ,EAAO,wBAAyBS,GAEnB,IAARA,EAEJ,OADAT,EAAO,qCACAK,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAEZE,EAAO,wBAAyBQ,GAChCR,EAAO,0BAA2BI,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdf,EAAO,kBAAmBkB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,GAPC,CAQD,CA5BDjB,EAAO,6BADPU,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJf,EAAO,2BAA4Be,EAAMM,SAClChB,EAAMU,KAGdf,EAAO,0CADPM,GAAS,EACgDG,GACpDC,EAAM,EACHG,IAEHP,IAAUG,GACdT,EAAO,qCACAK,EAAM,KAAMF,SAFpB,EAIA,CACF,CCxCA,SAASmB,EAAShC,EAASc,GAC1B,IAAIf,EACAkC,EACAC,EAGJ,GADAnC,EAAO,CAAA,EACFoC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMnC,EAAUC,EAAMC,GAErB,MAAMiC,EAEPC,EAAIpB,CACN,MACEoB,EAAIlC,EAEL,IAAMoC,EAAYF,GACjB,MAAM,IAAI5B,UAAWC,EAAQ,QAAS2B,IAUvC,YARqB,IAAhBnC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ6B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIN,UAAWC,EAAQ,QAASK,IAEvC,IAAMwB,EAAYrB,GACjB,MAAM,IAAIT,UAAWC,EAAQ,QAASQ,IAEvC,OAAOP,EAAOI,EAAY2B,EAASxC,EAAMmC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,EACZ,GACD,CACF,CC1EA,SAASyB,EAAkB1B,EAAY2B,EAASvC,EAASc,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAShC,EAATgC,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAShC,EAASc,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,EAC/C,CCnBA0B,EAAAC,EAAA,UAAAV"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 377bba2..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 13676cf2e39c77936f502031cc62346046b56283 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 May 2023 13:11:17 +0000 Subject: [PATCH 049/147] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 798 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 47 +- benchmark/benchmark.factory.js | 73 - benchmark/benchmark.js | 160 - branches.md | 53 - docs/repl.txt | 224 - docs/types/test.ts | 166 - examples/index.js | 55 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 165 - lib/index.js | 77 - lib/limit.js | 142 - lib/main.js | 96 - lib/validate.js | 80 - package.json | 64 +- stats.html | 6177 +++++++++++++++++++++ test/test.factory.js | 1095 ---- test/test.js | 38 - test/test.main.js | 1035 ---- test/test.validate.js | 181 - 44 files changed, 6208 insertions(+), 6809 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/limit.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 1527b20..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-05-01T04:11:27.071Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1e08946..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 663f5df..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 45a5053..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '37 1 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 3e8e2db..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,798 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -447,7 +446,7 @@ reduceRightAsync( files, acc, read, done ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -515,11 +514,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right +[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right/tree/esm -[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce +[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/tree/esm diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 46d8b83..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var reduceRightAsync; - var arr; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - reduceRightAsync = factory( onItem ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - var acc; - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 6ad0714..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var reduceRightAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=false', function benchmark( b ) { - var opts; - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'series': false - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var arr; - var len; - var acc; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'limit': 3 - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index acfc6d6..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right" -%% click B href "https://github.com/stdlib-js/utils-async-reduce-right/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-reduce-right/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-reduce-right/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-reduce-right/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right -[production-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3f22669..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,224 +0,0 @@ - -{{alias}}( collection, initial, [options,] reducer, done ) - Applies a function against an accumulator and each element in a collection - and returns the accumulated result, iterating from right to left. - - When invoked, `reducer` is provided a maximum of five arguments: - - - `accumulator`: accumulated value - - `value`: collection value - - `index`: collection index - - `collection`: the input collection - - `next`: a callback to be invoked after processing a collection `value` - - The actual number of provided arguments depends on function length. If - `reducer` accepts three arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `next` - - If `reducer` accepts four arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `index` - - `next` - - For every other `reducer` signature, `reducer` is provided all five - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `accumulator`: accumulated value - - If a provided function calls the `next` callback with a truthy `error` - argument, the function suspends execution and immediately calls the `done` - callback for subsequent `error` handling. - - Execution is *not* guaranteed to be asynchronous. To guarantee asynchrony, - 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`). - - The function does not support dynamic collection resizing. - - If provided an empty collection, the function invokes the `done` callback - with the `initial` value as the second argument. - - The function does not skip `undefined` elements. - - When processing collection elements concurrently, *beware* of race - conditions when updating an accumulator. This is especially true when an - accumulator is a primitive (e.g., a number). In general, prefer object - accumulators. - - Parameters - ---------- - collection: Array|TypedArray|Object - Input collection over which to iterate. If provided an object, the - object must be array-like (excluding strings and functions). - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - reducer: Function - The function to invoke for each element in a collection. - - done: Function - A callback invoked either upon processing all collection elements or - upon encountering an error. - - Examples - -------- - // Basic usage: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, fcn, done ) - 3000 - 2500 - 1000 - 6500 - - // Limit number of concurrent invocations: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'limit': 2 }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 2500 - 3000 - 1000 - 6500 - - // Process concurrently: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'series': false }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 1000 - 2500 - 3000 - 6500 - - -{{alias}}.factory( [options,] fcn ) - Returns a function which applies a function against an accumulator and each - element in a collection and returns the accumulated result, iterating from - right to left. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - fcn: Function - The function to invoke for each element in a collection. - - Returns - ------- - out: Function - A function which invokes a function for each element in a collection. - - Examples - -------- - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > var opts = { 'series': false }; - > var f = {{alias}}.factory( opts, fcn ); - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > f( arr, acc, done ) - 1000 - 2500 - 3000 - 6500 - > acc = { 'sum': 0 }; - > arr = [ 1000, 1500, 2000 ]; - > f( arr, acc, done ) - 1000 - 1500 - 2000 - 4500 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 143a132..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,166 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unsafe-any */ - -import reduceRightAsync = require( './index' ); - -const reducer = ( acc: any, value: number, index: number, next: Function ) => { - acc.sum += value; - if ( index === void 0 ) { - throw new Error( '`index` is missing.' ); - } - next( null, acc ); -}; - -const done = ( error: Error | null, acc: any ) => { - if ( error ) { - throw error; - } - if ( acc === void 0 ) { - throw new Error( '`acc` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( 2, acc, reducer, done ); // $ExpectError - reduceRightAsync( false, acc, reducer, done ); // $ExpectError - reduceRightAsync( true, acc, reducer, done ); // $ExpectError - reduceRightAsync( {}, acc, reducer, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a predicate argument which is not a predicate function... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 2, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, false, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, true, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 'abc', done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, [], done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a done callback argument which is not a function having a supported signature... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 2 ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, false ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, true ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 'abc' ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, {} ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, [] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const acc = { 'sum': 0 }; - reduceRightAsync(); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, reducer, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - reduceRightAsync.factory( reducer ); // $ExpectType FactoryFunction - reduceRightAsync.factory( { 'series': true }, reducer ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - reduceRightAsync.factory( [], reducer ); // $ExpectError - reduceRightAsync.factory( 123, reducer ); // $ExpectError - reduceRightAsync.factory( 'abc', reducer ); // $ExpectError - reduceRightAsync.factory( false, reducer ); // $ExpectError - reduceRightAsync.factory( true, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not a predicate function... -{ - reduceRightAsync.factory( {} ); // $ExpectError - reduceRightAsync.factory( true ); // $ExpectError - reduceRightAsync.factory( false ); // $ExpectError - reduceRightAsync.factory( {}, 123 ); // $ExpectError - reduceRightAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1( 12, acc, done ); // $ExpectError - fcn1( true, acc, done ); // $ExpectError - fcn1( false, acc, done ); // $ExpectError - fcn1( {}, acc, done ); // $ExpectError - - fcn1( [ 3000, 2500, 1000 ], acc, 12 ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, true ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, false ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, '5' ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, {} ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, [] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1(); // $ExpectError - fcn1( [ 3000, 2500, 1000 ] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - reduceRightAsync.factory( { 'limit': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': true }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': false }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - reduceRightAsync.factory( { 'series': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': 12 }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - reduceRightAsync.factory(); // $ExpectError - reduceRightAsync.factory( {}, reducer, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index dd64345..0000000 --- a/examples/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var resolve = require( 'path' ).resolve; -var readFile = require( '@stdlib/fs-read-file' ); -var reduceRightAsync = require( './../lib' ); - -var files = [ - resolve( __dirname, '..', 'package.json' ), - resolve( __dirname, '..', 'README.md' ) -]; - -function done( error, acc ) { - if ( error ) { - throw error; - } - console.log( acc.count ); -} - -function read( acc, file, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( file, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( null, acc ); - } - acc.count += 1; - next( null, acc ); - } -} - -var acc = { - 'count': 0 -}; -reduceRightAsync( files, acc, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index b19e443..9dc0658 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { Collection } from '@stdlib/types/object'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..2270aa3 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.8-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";function m(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("0id30","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!d(e.limit))?new TypeError(r("0id3b","limit",e.limit)):null):new TypeError(r("0id2h",t))}function c(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){if(this instanceof e){var i=[null];i.push.apply(i,arguments);var r=Function.bind.apply(t,i);return new r}return t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var f=c(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function p(e,t,i,r,s){var n,o,l,d,m,c;if(d=e.length,f("Collection length: %d",d),0===d)return f("Finished processing a collection."),s(null,t);for(l=d0&&p();function p(){function s(e,i){if(!o){if(e)return o=!0,u(e);f("Accumulator: %s",JSON.stringify(i)),t=i,u()}}f("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function u(e){return e?(f("Encountered an error: %s",e.message),s(e)):(f("Processed %d of %d collection elements.",n+=1,d),m>0?p():n===d?(f("Finished processing a collection."),s(null,t)):void 0)}}function u(e,n){var o,l,d;if(o={},arguments.length>1){if(l=m(o,e))throw l;d=n}else d=e;if(!t(d))throw new TypeError(r("0id43",d));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=s),c;function c(e,s,n){if(!i(e))throw new TypeError(r("0idBO",e));if(!t(n))throw new TypeError(r("0id43",n));return p(e,s,o,d,(function(e,t){if(e)return n(e);n(null,t)}))}}function a(e,t,i,r,s){if(arguments.length<5)return u(i)(e,t,r);u(i,r)(e,t,s)}e(a,"factory",u);export{a as default,u as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..63e894f --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '0id2h', 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( '0id30', '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( '0id3b', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0id43', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '0idBO', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0id43', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\n* @param {Collection} collection - input collection\n* @param {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","logger","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly","main"],"mappings":";;u2BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUR,EAAKK,SAGnDF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASR,EAAKS,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASP,GAkBzC,8eC/CIU,uDAAQC,CAAQ,4BAkBpB,SAASH,EAAOI,EAAYC,EAAKd,EAAMe,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMP,EAAWU,OACjBZ,EAAO,wBAAyBS,GAEnB,IAARA,EAEJ,OADAT,EAAO,qCACAK,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAEZE,EAAO,wBAAyBQ,GAChCR,EAAO,0BAA2BI,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdf,EAAO,kBAAmBkB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,GAPC,CAQD,CA5BDjB,EAAO,6BADPU,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJf,EAAO,2BAA4Be,EAAMM,SAClChB,EAAMU,KAGdf,EAAO,0CADPM,GAAS,EACgDG,GACpDC,EAAM,EACHG,IAEHP,IAAUG,GACdT,EAAO,qCACAK,EAAM,KAAMF,SAFpB,EAIA,CACF,CCxCA,SAASmB,EAAShC,EAASc,GAC1B,IAAIf,EACAkC,EACAC,EAGJ,GADAnC,EAAO,CAAA,EACFoC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMnC,EAAUC,EAAMC,GAErB,MAAMiC,EAEPC,EAAIpB,CACN,MACEoB,EAAIlC,EAEL,IAAMoC,EAAYF,GACjB,MAAM,IAAI5B,UAAWC,EAAQ,QAAS2B,IAUvC,YARqB,IAAhBnC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ6B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIN,UAAWC,EAAQ,QAASK,IAEvC,IAAMwB,EAAYrB,GACjB,MAAM,IAAIT,UAAWC,EAAQ,QAASQ,IAEvC,OAAOP,EAAOI,EAAY2B,EAASxC,EAAMmC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,EACZ,GACD,CACF,CC1EA,SAASyB,EAAkB1B,EAAY2B,EAASvC,EAASc,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAShC,EAATgC,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAShC,EAASc,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,EAC/C,CCnBA0B,EAAAC,EAAA,UAAAV"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 6d67be2..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var validate = require( './validate.js' ); -var limit = require( './limit.js' ); - - -// MAIN // - -/** -* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} last argument must be a function -* @returns {Function} function which invokes the provided function once for each element in a collection -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error, data ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var opts = { -* 'series': false -* }; -* -* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: -* var reduceRightAsync = factory( opts, read ); -* -* // Create a collection over which to iterate: -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* // Define a callback which handles errors: -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* // Run `read` for each element in `files`: -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, done ); -*/ -function factory( options, fcn ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = fcn; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '0id43', f ) ); - } - if ( opts.series === void 0 && opts.limit === void 0 ) { - opts.series = true; - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return reduceRightAsync; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * @private - * @param {Collection} collection - input collection - * @param {*} initial - initial value - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be a collection - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function reduceRightAsync( collection, initial, done ) { - if ( !isCollection( collection ) ) { - throw new TypeError( format( '0idBO', collection ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '0id43', done ) ); - } - return limit( collection, initial, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {*} [acc] - accumulated value - * @returns {void} - */ - function clbk( error, acc ) { - if ( error ) { - return done( error ); - } - done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ae657ff..0000000 --- a/lib/index.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* @module @stdlib/utils-async-reduce-right -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' ); -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/limit.js b/lib/limit.js deleted file mode 100644 index cdb60af..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); - - -// VARIABLES // - -var debug = logger( 'reduce-right-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each element in a collection, limiting the number of concurrently pending functions and iterating from right to left. -* -* @private -* @param {Collection} collection - input collection -* @param {*} acc - initial value -* @param {Options} opts - function options -* @param {*} [opts.thisArg] - execution context -* @param {PositiveInteger} [opts.limit] - maximum number of pending function invocations -* @param {Function} fcn - function to invoke -* @param {Callback} done - function to invoke upon completion or upon encountering an error -* @returns {void} -*/ -function limit( collection, acc, opts, fcn, done ) { - var count; - var flg; - var lim; - var len; - var idx; - var i; - - len = collection.length; - debug( 'Collection length: %d', len ); - - if ( len === 0 ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - count = 0; - idx = len; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all collection elements... - if ( idx > 0 ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next element in a collection. - * - * @private - */ - function next() { - idx -= 1; - debug( 'Collection element %d: %s.', idx, JSON.stringify( collection[ idx ] ) ); - if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], cb ); - } else if ( fcn.length === 4 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, cb ); - } else { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len - } - /** - * Callback invoked once a provided function finishes processing a collection element. - * - * @private - * @param {*} [error] - error - * @param {*} [result] - accumulation result - * @returns {void} - */ - function cb( error, result ) { - if ( flg ) { - // Prevent further processing of collection elements: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Accumulator: %s', JSON.stringify( result ) ); - acc = result; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next collection element. - * - * @private - * @param {*} [error] - error - * @returns {void} - */ - function clbk( error ) { - if ( error ) { - debug( 'Encountered an error: %s', error.message ); - return done( error ); - } - count += 1; - debug( 'Processed %d of %d collection elements.', count, len ); - if ( idx > 0 ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 9f016bf..0000000 --- a/lib/main.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param {Collection} collection - input collection -* @param {*} initial - initial value -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} second-to-last argument must be a function -* @throws {TypeError} last argument must be a function -* @returns {void} -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -function reduceRightAsync( collection, initial, options, fcn, done ) { - if ( arguments.length < 5 ) { - return factory( options )( collection, initial, fcn ); - } - factory( options, fcn )( collection, initial, done ); -} - - -// EXPORTS // - -module.exports = reduceRightAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 6292663..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @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 -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'thisArg': {}, -* 'series': false, -* 'limit': 10 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '0id2h', options ) ); - } - if ( hasOwnProp( options, 'thisArg' ) ) { - opts.thisArg = options.thisArg; - } - if ( hasOwnProp( options, 'series' ) ) { - opts.series = options.series; - if ( !isBoolean( opts.series ) ) { - return new TypeError( format( '0id30', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '0id3b', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 8660367..cfe057f 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.8", "description": "Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,43 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.0.7", - "@stdlib/assert-is-boolean": "^0.0.8", - "@stdlib/assert-is-collection": "^0.0.8", - "@stdlib/assert-is-function": "^0.0.8", - "@stdlib/assert-is-plain-object": "^0.0.7", - "@stdlib/assert-is-positive-integer": "^0.0.7", - "@stdlib/constants-float64-pinf": "^0.0.8", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/types": "^0.0.14", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.12", - "@stdlib/constants-float64-eps": "^0.0.8", - "@stdlib/fs-read-file": "^0.0.8", - "@stdlib/utils-noop": "^0.0.14", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..33e6620 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 8244931..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1095 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( {}, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, next ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - factory( opts, next ); - }; - } -}); - -tape( 'the function returns a function (no options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided a collection (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a collection (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (1 argument)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (2 arguments)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with five arguments', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn() { - var value; - var next; - var acc; - var k; - - acc = arguments[ 0 ]; - value = arguments[ 1 ]; - k = arguments[ 2 ]; - next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( k, i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the returned function supports processing collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements concurrently', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 100, 250, 300 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements sequentially (limit = 1)', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of collection elements which are processed at any one time', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 250, 300, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 250, 100, 300 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var reduceRightAsync; - var arr; - - reduceRightAsync = factory( fcn ); - arr = []; - - reduceRightAsync( arr, 0, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var reduceRightAsync; - var obj; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = []; - obj = {}; - reduceRightAsync( arr, obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - i = 0; - - reduceRightAsync( arr, {}, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, acc ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the returned function does not skip empty elements', function test( t ) { - var reduceRightAsync; - var expected; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index f273a40..0000000 --- a/test/test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof reduceRightAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 1893240..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1035 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a collection', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (no options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, next, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, 0 ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - reduceRightAsync( [ 1, 2, 3 ], 0, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (1 argument)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (2 arguments)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with five arguments', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn() { - var next; - var acc; - var v; - - next = arguments[ 4 ]; - acc = arguments[ 0 ]; - v = arguments[ 1 ]; - - i -= 1; - j += 1; - - t.strictEqual( v, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, v ); - - function onTimeout() { - acc.sum += v; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'by default, the function processes collection elements sequentially', function test( t ) { - var values; - var count; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements concurrently', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 100, 250, 300 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': true - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially (limit = 1)', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var arr; - var ctx; - - arr = [ 3, 2, 1 ]; - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 3, 2, 1 ]; - opts = { - 'series': true - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 250, 100, 300 ]; - opts = { - 'limit': 2 - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var arr = []; - reduceRightAsync( arr, 0, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var arr = []; - var obj = {}; - - reduceRightAsync( arr, obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - arr = [ 3, 2, 1 ]; - i = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, value ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the function does not skip empty elements', function test( t ) { - var expected; - var arr; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, fcn, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 7660838..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,181 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `limit` option which is not a positive integer', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - -5, - 0, - 3.14, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'limit': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `series` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'series': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function accepts any value for the `thisArg` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'thisArg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err, null, 'returns null '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'thisArg': {}, - 'series': false, - 'limit': 10 - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From 56ff97fae9352a9790234d4f4159d8480e1040c5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Jun 2023 05:57:27 +0000 Subject: [PATCH 050/147] Transform error messages --- lib/factory.js | 8 ++++---- lib/validate.js | 8 ++++---- package.json | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index a627d69..6d67be2 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -22,7 +22,7 @@ var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var PINF = require( '@stdlib/constants-float64-pinf' ); var validate = require( './validate.js' ); var limit = require( './limit.js' ); @@ -110,7 +110,7 @@ function factory( options, fcn ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '0id43', f ) ); } if ( opts.series === void 0 && opts.limit === void 0 ) { opts.series = true; @@ -135,10 +135,10 @@ function factory( options, fcn ) { */ function reduceRightAsync( collection, initial, done ) { if ( !isCollection( collection ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a collection. Value: `%s`.', collection ) ); + throw new TypeError( format( '0idBO', collection ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '0id43', done ) ); } return limit( collection, initial, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index 9ba927e..6292663 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,7 +54,7 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0id2h', options ) ); } if ( hasOwnProp( options, 'thisArg' ) ) { opts.thisArg = options.thisArg; @@ -62,13 +62,13 @@ function validate( opts, options ) { if ( hasOwnProp( options, 'series' ) ) { opts.series = options.series; if ( !isBoolean( opts.series ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'series', opts.series ) ); + return new TypeError( format( '0id30', 'series', opts.series ) ); } } if ( hasOwnProp( options, 'limit' ) ) { opts.limit = options.limit; if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'limit', opts.limit ) ); + return new TypeError( format( '0id3b', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index e0057f8..8660367 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-plain-object": "^0.0.7", "@stdlib/assert-is-positive-integer": "^0.0.7", "@stdlib/constants-float64-pinf": "^0.0.8", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/types": "^0.0.14", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7", "debug": "^2.6.9" From 80382cf611d2302881f8a5a87c31b63dbe31e61c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Jun 2023 13:33:05 +0000 Subject: [PATCH 051/147] Remove files --- index.d.ts | 415 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6597 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 9dc0658..0000000 --- a/index.d.ts +++ /dev/null @@ -1,415 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Collection } from '@stdlib/types/object'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * The maximum number of pending invocations at any one time. - */ - limit?: number; - - /** - * Boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection (default: true). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback function. -*/ -type Nullary = () => void; - -/** -* Callback function. -* -* @param error - encountered error or null -*/ -type Unary = ( error: Error | null ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Binary = ( error: Error | null, accumulator: any ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param next - a callback to be invoked after processing a collection `value` -*/ -type TernaryReducer = ( accumulator: any, value: any, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuaternaryReducer = ( accumulator: any, value: any, index: number, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuinaryReducer = ( accumulator: any, value: any, index: number, collection: Collection, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type Reducer = TernaryReducer | QuaternaryReducer | QuinaryReducer; - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result. -* -* @param collection - input collection -* @param initial - initial value -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( collection: Collection, initial: any, done: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Interface for `reduceRightAsync`. -*/ -interface ReduceRightAsync { - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, {}, read, done ); - */ - ( collection: Collection, initial: any, options: Options, reducer: Reducer, done: Callback ): void; // tslint-disable-line max-line-length - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, read, done ); - */ - ( collection: Collection, initial: any, reducer: Reducer, done: Callback ): void; // tslint-disable-line max-line-length - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @throws must provide valid options - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var opts = { - * 'series': false - * }; - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( opts, read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( options: Options, reducer: Reducer ): FactoryFunction; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param reducer - function to invoke for each element in a collection - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( reducer: Reducer ): FactoryFunction; -} - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param collection - input collection -* @param initial - initial value -* @param options - function options -* @param options.thisArg - execution context -* @param options.limit - maximum number of pending invocations at any one time -* @param 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 (default: true) -* @param reducer - function to invoke for each element in a collection -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( `@stdlib/fs/read-file` ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -declare var reduceRightAsync: ReduceRightAsync; - - -// EXPORTS // - -export = reduceRightAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 2270aa3..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.8-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";function m(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("0id30","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!d(e.limit))?new TypeError(r("0id3b","limit",e.limit)):null):new TypeError(r("0id2h",t))}function c(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){if(this instanceof e){var i=[null];i.push.apply(i,arguments);var r=Function.bind.apply(t,i);return new r}return t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var f=c(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function p(e,t,i,r,s){var n,o,l,d,m,c;if(d=e.length,f("Collection length: %d",d),0===d)return f("Finished processing a collection."),s(null,t);for(l=d0&&p();function p(){function s(e,i){if(!o){if(e)return o=!0,u(e);f("Accumulator: %s",JSON.stringify(i)),t=i,u()}}f("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function u(e){return e?(f("Encountered an error: %s",e.message),s(e)):(f("Processed %d of %d collection elements.",n+=1,d),m>0?p():n===d?(f("Finished processing a collection."),s(null,t)):void 0)}}function u(e,n){var o,l,d;if(o={},arguments.length>1){if(l=m(o,e))throw l;d=n}else d=e;if(!t(d))throw new TypeError(r("0id43",d));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=s),c;function c(e,s,n){if(!i(e))throw new TypeError(r("0idBO",e));if(!t(n))throw new TypeError(r("0id43",n));return p(e,s,o,d,(function(e,t){if(e)return n(e);n(null,t)}))}}function a(e,t,i,r,s){if(arguments.length<5)return u(i)(e,t,r);u(i,r)(e,t,s)}e(a,"factory",u);export{a as default,u as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 63e894f..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '0id2h', 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( '0id30', '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( '0id3b', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0id43', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '0idBO', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0id43', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\n* @param {Collection} collection - input collection\n* @param {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","logger","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly","main"],"mappings":";;u2BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUR,EAAKK,SAGnDF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASR,EAAKS,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASP,GAkBzC,8eC/CIU,uDAAQC,CAAQ,4BAkBpB,SAASH,EAAOI,EAAYC,EAAKd,EAAMe,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMP,EAAWU,OACjBZ,EAAO,wBAAyBS,GAEnB,IAARA,EAEJ,OADAT,EAAO,qCACAK,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAEZE,EAAO,wBAAyBQ,GAChCR,EAAO,0BAA2BI,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdf,EAAO,kBAAmBkB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,GAPC,CAQD,CA5BDjB,EAAO,6BADPU,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJf,EAAO,2BAA4Be,EAAMM,SAClChB,EAAMU,KAGdf,EAAO,0CADPM,GAAS,EACgDG,GACpDC,EAAM,EACHG,IAEHP,IAAUG,GACdT,EAAO,qCACAK,EAAM,KAAMF,SAFpB,EAIA,CACF,CCxCA,SAASmB,EAAShC,EAASc,GAC1B,IAAIf,EACAkC,EACAC,EAGJ,GADAnC,EAAO,CAAA,EACFoC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMnC,EAAUC,EAAMC,GAErB,MAAMiC,EAEPC,EAAIpB,CACN,MACEoB,EAAIlC,EAEL,IAAMoC,EAAYF,GACjB,MAAM,IAAI5B,UAAWC,EAAQ,QAAS2B,IAUvC,YARqB,IAAhBnC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ6B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIN,UAAWC,EAAQ,QAASK,IAEvC,IAAMwB,EAAYrB,GACjB,MAAM,IAAIT,UAAWC,EAAQ,QAASQ,IAEvC,OAAOP,EAAOI,EAAY2B,EAASxC,EAAMmC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,EACZ,GACD,CACF,CC1EA,SAASyB,EAAkB1B,EAAY2B,EAASvC,EAASc,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAShC,EAATgC,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAShC,EAASc,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,EAC/C,CCnBA0B,EAAAC,EAAA,UAAAV"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 33e6620..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From beb995c2b803e232f75e947fc867a2e0c709df04 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Jun 2023 13:33:44 +0000 Subject: [PATCH 052/147] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 798 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 47 +- benchmark/benchmark.factory.js | 73 - benchmark/benchmark.js | 160 - branches.md | 53 - docs/repl.txt | 224 - docs/types/test.ts | 166 - examples/index.js | 55 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 165 - lib/index.js | 77 - lib/limit.js | 142 - lib/main.js | 96 - lib/validate.js | 80 - package.json | 64 +- stats.html | 6177 +++++++++++++++++++++ test/test.factory.js | 1095 ---- test/test.js | 38 - test/test.main.js | 1035 ---- test/test.validate.js | 181 - 44 files changed, 6208 insertions(+), 6809 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/limit.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 202914e..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-06-01T03:51:47.517Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1e08946..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 663f5df..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 45a5053..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '37 1 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 3e8e2db..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,798 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -447,7 +446,7 @@ reduceRightAsync( files, acc, read, done ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -515,11 +514,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right +[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right/tree/esm -[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce +[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/tree/esm diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 46d8b83..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var reduceRightAsync; - var arr; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - reduceRightAsync = factory( onItem ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - var acc; - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 6ad0714..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var reduceRightAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=false', function benchmark( b ) { - var opts; - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'series': false - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var arr; - var len; - var acc; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'limit': 3 - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index acfc6d6..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right" -%% click B href "https://github.com/stdlib-js/utils-async-reduce-right/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-reduce-right/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-reduce-right/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-reduce-right/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right -[production-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3f22669..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,224 +0,0 @@ - -{{alias}}( collection, initial, [options,] reducer, done ) - Applies a function against an accumulator and each element in a collection - and returns the accumulated result, iterating from right to left. - - When invoked, `reducer` is provided a maximum of five arguments: - - - `accumulator`: accumulated value - - `value`: collection value - - `index`: collection index - - `collection`: the input collection - - `next`: a callback to be invoked after processing a collection `value` - - The actual number of provided arguments depends on function length. If - `reducer` accepts three arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `next` - - If `reducer` accepts four arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `index` - - `next` - - For every other `reducer` signature, `reducer` is provided all five - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `accumulator`: accumulated value - - If a provided function calls the `next` callback with a truthy `error` - argument, the function suspends execution and immediately calls the `done` - callback for subsequent `error` handling. - - Execution is *not* guaranteed to be asynchronous. To guarantee asynchrony, - 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`). - - The function does not support dynamic collection resizing. - - If provided an empty collection, the function invokes the `done` callback - with the `initial` value as the second argument. - - The function does not skip `undefined` elements. - - When processing collection elements concurrently, *beware* of race - conditions when updating an accumulator. This is especially true when an - accumulator is a primitive (e.g., a number). In general, prefer object - accumulators. - - Parameters - ---------- - collection: Array|TypedArray|Object - Input collection over which to iterate. If provided an object, the - object must be array-like (excluding strings and functions). - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - reducer: Function - The function to invoke for each element in a collection. - - done: Function - A callback invoked either upon processing all collection elements or - upon encountering an error. - - Examples - -------- - // Basic usage: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, fcn, done ) - 3000 - 2500 - 1000 - 6500 - - // Limit number of concurrent invocations: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'limit': 2 }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 2500 - 3000 - 1000 - 6500 - - // Process concurrently: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'series': false }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 1000 - 2500 - 3000 - 6500 - - -{{alias}}.factory( [options,] fcn ) - Returns a function which applies a function against an accumulator and each - element in a collection and returns the accumulated result, iterating from - right to left. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - fcn: Function - The function to invoke for each element in a collection. - - Returns - ------- - out: Function - A function which invokes a function for each element in a collection. - - Examples - -------- - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > var opts = { 'series': false }; - > var f = {{alias}}.factory( opts, fcn ); - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > f( arr, acc, done ) - 1000 - 2500 - 3000 - 6500 - > acc = { 'sum': 0 }; - > arr = [ 1000, 1500, 2000 ]; - > f( arr, acc, done ) - 1000 - 1500 - 2000 - 4500 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 143a132..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,166 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unsafe-any */ - -import reduceRightAsync = require( './index' ); - -const reducer = ( acc: any, value: number, index: number, next: Function ) => { - acc.sum += value; - if ( index === void 0 ) { - throw new Error( '`index` is missing.' ); - } - next( null, acc ); -}; - -const done = ( error: Error | null, acc: any ) => { - if ( error ) { - throw error; - } - if ( acc === void 0 ) { - throw new Error( '`acc` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( 2, acc, reducer, done ); // $ExpectError - reduceRightAsync( false, acc, reducer, done ); // $ExpectError - reduceRightAsync( true, acc, reducer, done ); // $ExpectError - reduceRightAsync( {}, acc, reducer, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a predicate argument which is not a predicate function... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 2, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, false, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, true, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 'abc', done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, [], done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a done callback argument which is not a function having a supported signature... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 2 ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, false ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, true ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 'abc' ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, {} ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, [] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const acc = { 'sum': 0 }; - reduceRightAsync(); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, reducer, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - reduceRightAsync.factory( reducer ); // $ExpectType FactoryFunction - reduceRightAsync.factory( { 'series': true }, reducer ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - reduceRightAsync.factory( [], reducer ); // $ExpectError - reduceRightAsync.factory( 123, reducer ); // $ExpectError - reduceRightAsync.factory( 'abc', reducer ); // $ExpectError - reduceRightAsync.factory( false, reducer ); // $ExpectError - reduceRightAsync.factory( true, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not a predicate function... -{ - reduceRightAsync.factory( {} ); // $ExpectError - reduceRightAsync.factory( true ); // $ExpectError - reduceRightAsync.factory( false ); // $ExpectError - reduceRightAsync.factory( {}, 123 ); // $ExpectError - reduceRightAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1( 12, acc, done ); // $ExpectError - fcn1( true, acc, done ); // $ExpectError - fcn1( false, acc, done ); // $ExpectError - fcn1( {}, acc, done ); // $ExpectError - - fcn1( [ 3000, 2500, 1000 ], acc, 12 ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, true ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, false ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, '5' ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, {} ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, [] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1(); // $ExpectError - fcn1( [ 3000, 2500, 1000 ] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - reduceRightAsync.factory( { 'limit': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': true }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': false }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - reduceRightAsync.factory( { 'series': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': 12 }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - reduceRightAsync.factory(); // $ExpectError - reduceRightAsync.factory( {}, reducer, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index dd64345..0000000 --- a/examples/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var resolve = require( 'path' ).resolve; -var readFile = require( '@stdlib/fs-read-file' ); -var reduceRightAsync = require( './../lib' ); - -var files = [ - resolve( __dirname, '..', 'package.json' ), - resolve( __dirname, '..', 'README.md' ) -]; - -function done( error, acc ) { - if ( error ) { - throw error; - } - console.log( acc.count ); -} - -function read( acc, file, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( file, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( null, acc ); - } - acc.count += 1; - next( null, acc ); - } -} - -var acc = { - 'count': 0 -}; -reduceRightAsync( files, acc, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index b19e443..9dc0658 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { Collection } from '@stdlib/types/object'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..2270aa3 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.8-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";function m(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("0id30","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!d(e.limit))?new TypeError(r("0id3b","limit",e.limit)):null):new TypeError(r("0id2h",t))}function c(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){if(this instanceof e){var i=[null];i.push.apply(i,arguments);var r=Function.bind.apply(t,i);return new r}return t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var f=c(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function p(e,t,i,r,s){var n,o,l,d,m,c;if(d=e.length,f("Collection length: %d",d),0===d)return f("Finished processing a collection."),s(null,t);for(l=d0&&p();function p(){function s(e,i){if(!o){if(e)return o=!0,u(e);f("Accumulator: %s",JSON.stringify(i)),t=i,u()}}f("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function u(e){return e?(f("Encountered an error: %s",e.message),s(e)):(f("Processed %d of %d collection elements.",n+=1,d),m>0?p():n===d?(f("Finished processing a collection."),s(null,t)):void 0)}}function u(e,n){var o,l,d;if(o={},arguments.length>1){if(l=m(o,e))throw l;d=n}else d=e;if(!t(d))throw new TypeError(r("0id43",d));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=s),c;function c(e,s,n){if(!i(e))throw new TypeError(r("0idBO",e));if(!t(n))throw new TypeError(r("0id43",n));return p(e,s,o,d,(function(e,t){if(e)return n(e);n(null,t)}))}}function a(e,t,i,r,s){if(arguments.length<5)return u(i)(e,t,r);u(i,r)(e,t,s)}e(a,"factory",u);export{a as default,u as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..63e894f --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '0id2h', 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( '0id30', '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( '0id3b', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0id43', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '0idBO', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0id43', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\n* @param {Collection} collection - input collection\n* @param {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","logger","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly","main"],"mappings":";;u2BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUR,EAAKK,SAGnDF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASR,EAAKS,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASP,GAkBzC,8eC/CIU,uDAAQC,CAAQ,4BAkBpB,SAASH,EAAOI,EAAYC,EAAKd,EAAMe,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMP,EAAWU,OACjBZ,EAAO,wBAAyBS,GAEnB,IAARA,EAEJ,OADAT,EAAO,qCACAK,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAEZE,EAAO,wBAAyBQ,GAChCR,EAAO,0BAA2BI,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdf,EAAO,kBAAmBkB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,GAPC,CAQD,CA5BDjB,EAAO,6BADPU,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJf,EAAO,2BAA4Be,EAAMM,SAClChB,EAAMU,KAGdf,EAAO,0CADPM,GAAS,EACgDG,GACpDC,EAAM,EACHG,IAEHP,IAAUG,GACdT,EAAO,qCACAK,EAAM,KAAMF,SAFpB,EAIA,CACF,CCxCA,SAASmB,EAAShC,EAASc,GAC1B,IAAIf,EACAkC,EACAC,EAGJ,GADAnC,EAAO,CAAA,EACFoC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMnC,EAAUC,EAAMC,GAErB,MAAMiC,EAEPC,EAAIpB,CACN,MACEoB,EAAIlC,EAEL,IAAMoC,EAAYF,GACjB,MAAM,IAAI5B,UAAWC,EAAQ,QAAS2B,IAUvC,YARqB,IAAhBnC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ6B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIN,UAAWC,EAAQ,QAASK,IAEvC,IAAMwB,EAAYrB,GACjB,MAAM,IAAIT,UAAWC,EAAQ,QAASQ,IAEvC,OAAOP,EAAOI,EAAY2B,EAASxC,EAAMmC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,EACZ,GACD,CACF,CC1EA,SAASyB,EAAkB1B,EAAY2B,EAASvC,EAASc,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAShC,EAATgC,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAShC,EAASc,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,EAC/C,CCnBA0B,EAAAC,EAAA,UAAAV"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 6d67be2..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var validate = require( './validate.js' ); -var limit = require( './limit.js' ); - - -// MAIN // - -/** -* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} last argument must be a function -* @returns {Function} function which invokes the provided function once for each element in a collection -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error, data ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var opts = { -* 'series': false -* }; -* -* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: -* var reduceRightAsync = factory( opts, read ); -* -* // Create a collection over which to iterate: -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* // Define a callback which handles errors: -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* // Run `read` for each element in `files`: -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, done ); -*/ -function factory( options, fcn ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = fcn; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '0id43', f ) ); - } - if ( opts.series === void 0 && opts.limit === void 0 ) { - opts.series = true; - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return reduceRightAsync; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * @private - * @param {Collection} collection - input collection - * @param {*} initial - initial value - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be a collection - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function reduceRightAsync( collection, initial, done ) { - if ( !isCollection( collection ) ) { - throw new TypeError( format( '0idBO', collection ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '0id43', done ) ); - } - return limit( collection, initial, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {*} [acc] - accumulated value - * @returns {void} - */ - function clbk( error, acc ) { - if ( error ) { - return done( error ); - } - done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ae657ff..0000000 --- a/lib/index.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* @module @stdlib/utils-async-reduce-right -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' ); -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/limit.js b/lib/limit.js deleted file mode 100644 index cdb60af..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); - - -// VARIABLES // - -var debug = logger( 'reduce-right-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each element in a collection, limiting the number of concurrently pending functions and iterating from right to left. -* -* @private -* @param {Collection} collection - input collection -* @param {*} acc - initial value -* @param {Options} opts - function options -* @param {*} [opts.thisArg] - execution context -* @param {PositiveInteger} [opts.limit] - maximum number of pending function invocations -* @param {Function} fcn - function to invoke -* @param {Callback} done - function to invoke upon completion or upon encountering an error -* @returns {void} -*/ -function limit( collection, acc, opts, fcn, done ) { - var count; - var flg; - var lim; - var len; - var idx; - var i; - - len = collection.length; - debug( 'Collection length: %d', len ); - - if ( len === 0 ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - count = 0; - idx = len; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all collection elements... - if ( idx > 0 ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next element in a collection. - * - * @private - */ - function next() { - idx -= 1; - debug( 'Collection element %d: %s.', idx, JSON.stringify( collection[ idx ] ) ); - if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], cb ); - } else if ( fcn.length === 4 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, cb ); - } else { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len - } - /** - * Callback invoked once a provided function finishes processing a collection element. - * - * @private - * @param {*} [error] - error - * @param {*} [result] - accumulation result - * @returns {void} - */ - function cb( error, result ) { - if ( flg ) { - // Prevent further processing of collection elements: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Accumulator: %s', JSON.stringify( result ) ); - acc = result; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next collection element. - * - * @private - * @param {*} [error] - error - * @returns {void} - */ - function clbk( error ) { - if ( error ) { - debug( 'Encountered an error: %s', error.message ); - return done( error ); - } - count += 1; - debug( 'Processed %d of %d collection elements.', count, len ); - if ( idx > 0 ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 9f016bf..0000000 --- a/lib/main.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param {Collection} collection - input collection -* @param {*} initial - initial value -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} second-to-last argument must be a function -* @throws {TypeError} last argument must be a function -* @returns {void} -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -function reduceRightAsync( collection, initial, options, fcn, done ) { - if ( arguments.length < 5 ) { - return factory( options )( collection, initial, fcn ); - } - factory( options, fcn )( collection, initial, done ); -} - - -// EXPORTS // - -module.exports = reduceRightAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 6292663..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @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 -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'thisArg': {}, -* 'series': false, -* 'limit': 10 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '0id2h', options ) ); - } - if ( hasOwnProp( options, 'thisArg' ) ) { - opts.thisArg = options.thisArg; - } - if ( hasOwnProp( options, 'series' ) ) { - opts.series = options.series; - if ( !isBoolean( opts.series ) ) { - return new TypeError( format( '0id30', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '0id3b', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 8660367..cfe057f 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.8", "description": "Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,43 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.0.7", - "@stdlib/assert-is-boolean": "^0.0.8", - "@stdlib/assert-is-collection": "^0.0.8", - "@stdlib/assert-is-function": "^0.0.8", - "@stdlib/assert-is-plain-object": "^0.0.7", - "@stdlib/assert-is-positive-integer": "^0.0.7", - "@stdlib/constants-float64-pinf": "^0.0.8", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/types": "^0.0.14", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.12", - "@stdlib/constants-float64-eps": "^0.0.8", - "@stdlib/fs-read-file": "^0.0.8", - "@stdlib/utils-noop": "^0.0.14", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..061ad6c --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 8244931..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1095 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( {}, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, next ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - factory( opts, next ); - }; - } -}); - -tape( 'the function returns a function (no options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided a collection (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a collection (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (1 argument)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (2 arguments)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with five arguments', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn() { - var value; - var next; - var acc; - var k; - - acc = arguments[ 0 ]; - value = arguments[ 1 ]; - k = arguments[ 2 ]; - next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( k, i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the returned function supports processing collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements concurrently', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 100, 250, 300 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements sequentially (limit = 1)', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of collection elements which are processed at any one time', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 250, 300, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 250, 100, 300 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var reduceRightAsync; - var arr; - - reduceRightAsync = factory( fcn ); - arr = []; - - reduceRightAsync( arr, 0, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var reduceRightAsync; - var obj; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = []; - obj = {}; - reduceRightAsync( arr, obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - i = 0; - - reduceRightAsync( arr, {}, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, acc ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the returned function does not skip empty elements', function test( t ) { - var reduceRightAsync; - var expected; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index f273a40..0000000 --- a/test/test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof reduceRightAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 1893240..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1035 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a collection', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (no options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, next, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, 0 ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - reduceRightAsync( [ 1, 2, 3 ], 0, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (1 argument)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (2 arguments)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with five arguments', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn() { - var next; - var acc; - var v; - - next = arguments[ 4 ]; - acc = arguments[ 0 ]; - v = arguments[ 1 ]; - - i -= 1; - j += 1; - - t.strictEqual( v, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, v ); - - function onTimeout() { - acc.sum += v; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'by default, the function processes collection elements sequentially', function test( t ) { - var values; - var count; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements concurrently', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 100, 250, 300 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': true - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially (limit = 1)', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var arr; - var ctx; - - arr = [ 3, 2, 1 ]; - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 3, 2, 1 ]; - opts = { - 'series': true - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 250, 100, 300 ]; - opts = { - 'limit': 2 - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var arr = []; - reduceRightAsync( arr, 0, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var arr = []; - var obj = {}; - - reduceRightAsync( arr, obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - arr = [ 3, 2, 1 ]; - i = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, value ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the function does not skip empty elements', function test( t ) { - var expected; - var arr; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, fcn, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 7660838..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,181 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `limit` option which is not a positive integer', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - -5, - 0, - 3.14, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'limit': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `series` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'series': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function accepts any value for the `thisArg` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'thisArg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err, null, 'returns null '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'thisArg': {}, - 'series': false, - 'limit': 10 - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From a24b2d00966ca0e45556fc58ae2b172c4452f222 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jul 2023 05:59:59 +0000 Subject: [PATCH 053/147] Transform error messages --- lib/factory.js | 8 ++++---- lib/validate.js | 8 ++++---- package.json | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index a627d69..6d67be2 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -22,7 +22,7 @@ var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var PINF = require( '@stdlib/constants-float64-pinf' ); var validate = require( './validate.js' ); var limit = require( './limit.js' ); @@ -110,7 +110,7 @@ function factory( options, fcn ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '0id43', f ) ); } if ( opts.series === void 0 && opts.limit === void 0 ) { opts.series = true; @@ -135,10 +135,10 @@ function factory( options, fcn ) { */ function reduceRightAsync( collection, initial, done ) { if ( !isCollection( collection ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a collection. Value: `%s`.', collection ) ); + throw new TypeError( format( '0idBO', collection ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '0id43', done ) ); } return limit( collection, initial, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index 9ba927e..6292663 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,7 +54,7 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0id2h', options ) ); } if ( hasOwnProp( options, 'thisArg' ) ) { opts.thisArg = options.thisArg; @@ -62,13 +62,13 @@ function validate( opts, options ) { if ( hasOwnProp( options, 'series' ) ) { opts.series = options.series; if ( !isBoolean( opts.series ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'series', opts.series ) ); + return new TypeError( format( '0id30', 'series', opts.series ) ); } } if ( hasOwnProp( options, 'limit' ) ) { opts.limit = options.limit; if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'limit', opts.limit ) ); + return new TypeError( format( '0id3b', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index e0057f8..8660367 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-plain-object": "^0.0.7", "@stdlib/assert-is-positive-integer": "^0.0.7", "@stdlib/constants-float64-pinf": "^0.0.8", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/types": "^0.0.14", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7", "debug": "^2.6.9" From ecae07dd0f0a81a0de1d07e30f1c9b5e83e2838b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jul 2023 13:41:54 +0000 Subject: [PATCH 054/147] Remove files --- index.d.ts | 415 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6597 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 9dc0658..0000000 --- a/index.d.ts +++ /dev/null @@ -1,415 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Collection } from '@stdlib/types/object'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * The maximum number of pending invocations at any one time. - */ - limit?: number; - - /** - * Boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection (default: true). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback function. -*/ -type Nullary = () => void; - -/** -* Callback function. -* -* @param error - encountered error or null -*/ -type Unary = ( error: Error | null ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Binary = ( error: Error | null, accumulator: any ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param next - a callback to be invoked after processing a collection `value` -*/ -type TernaryReducer = ( accumulator: any, value: any, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuaternaryReducer = ( accumulator: any, value: any, index: number, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuinaryReducer = ( accumulator: any, value: any, index: number, collection: Collection, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type Reducer = TernaryReducer | QuaternaryReducer | QuinaryReducer; - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result. -* -* @param collection - input collection -* @param initial - initial value -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( collection: Collection, initial: any, done: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Interface for `reduceRightAsync`. -*/ -interface ReduceRightAsync { - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, {}, read, done ); - */ - ( collection: Collection, initial: any, options: Options, reducer: Reducer, done: Callback ): void; // tslint-disable-line max-line-length - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, read, done ); - */ - ( collection: Collection, initial: any, reducer: Reducer, done: Callback ): void; // tslint-disable-line max-line-length - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @throws must provide valid options - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var opts = { - * 'series': false - * }; - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( opts, read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( options: Options, reducer: Reducer ): FactoryFunction; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param reducer - function to invoke for each element in a collection - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( reducer: Reducer ): FactoryFunction; -} - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param collection - input collection -* @param initial - initial value -* @param options - function options -* @param options.thisArg - execution context -* @param options.limit - maximum number of pending invocations at any one time -* @param 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 (default: true) -* @param reducer - function to invoke for each element in a collection -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( `@stdlib/fs/read-file` ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -declare var reduceRightAsync: ReduceRightAsync; - - -// EXPORTS // - -export = reduceRightAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 2270aa3..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.8-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";function m(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("0id30","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!d(e.limit))?new TypeError(r("0id3b","limit",e.limit)):null):new TypeError(r("0id2h",t))}function c(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){if(this instanceof e){var i=[null];i.push.apply(i,arguments);var r=Function.bind.apply(t,i);return new r}return t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var f=c(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function p(e,t,i,r,s){var n,o,l,d,m,c;if(d=e.length,f("Collection length: %d",d),0===d)return f("Finished processing a collection."),s(null,t);for(l=d0&&p();function p(){function s(e,i){if(!o){if(e)return o=!0,u(e);f("Accumulator: %s",JSON.stringify(i)),t=i,u()}}f("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function u(e){return e?(f("Encountered an error: %s",e.message),s(e)):(f("Processed %d of %d collection elements.",n+=1,d),m>0?p():n===d?(f("Finished processing a collection."),s(null,t)):void 0)}}function u(e,n){var o,l,d;if(o={},arguments.length>1){if(l=m(o,e))throw l;d=n}else d=e;if(!t(d))throw new TypeError(r("0id43",d));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=s),c;function c(e,s,n){if(!i(e))throw new TypeError(r("0idBO",e));if(!t(n))throw new TypeError(r("0id43",n));return p(e,s,o,d,(function(e,t){if(e)return n(e);n(null,t)}))}}function a(e,t,i,r,s){if(arguments.length<5)return u(i)(e,t,r);u(i,r)(e,t,s)}e(a,"factory",u);export{a as default,u as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 63e894f..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '0id2h', 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( '0id30', '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( '0id3b', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0id43', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '0idBO', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0id43', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\n* @param {Collection} collection - input collection\n* @param {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","logger","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly","main"],"mappings":";;u2BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUR,EAAKK,SAGnDF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASR,EAAKS,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASP,GAkBzC,8eC/CIU,uDAAQC,CAAQ,4BAkBpB,SAASH,EAAOI,EAAYC,EAAKd,EAAMe,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMP,EAAWU,OACjBZ,EAAO,wBAAyBS,GAEnB,IAARA,EAEJ,OADAT,EAAO,qCACAK,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAEZE,EAAO,wBAAyBQ,GAChCR,EAAO,0BAA2BI,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdf,EAAO,kBAAmBkB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,GAPC,CAQD,CA5BDjB,EAAO,6BADPU,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJf,EAAO,2BAA4Be,EAAMM,SAClChB,EAAMU,KAGdf,EAAO,0CADPM,GAAS,EACgDG,GACpDC,EAAM,EACHG,IAEHP,IAAUG,GACdT,EAAO,qCACAK,EAAM,KAAMF,SAFpB,EAIA,CACF,CCxCA,SAASmB,EAAShC,EAASc,GAC1B,IAAIf,EACAkC,EACAC,EAGJ,GADAnC,EAAO,CAAA,EACFoC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMnC,EAAUC,EAAMC,GAErB,MAAMiC,EAEPC,EAAIpB,CACN,MACEoB,EAAIlC,EAEL,IAAMoC,EAAYF,GACjB,MAAM,IAAI5B,UAAWC,EAAQ,QAAS2B,IAUvC,YARqB,IAAhBnC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ6B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIN,UAAWC,EAAQ,QAASK,IAEvC,IAAMwB,EAAYrB,GACjB,MAAM,IAAIT,UAAWC,EAAQ,QAASQ,IAEvC,OAAOP,EAAOI,EAAY2B,EAASxC,EAAMmC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,EACZ,GACD,CACF,CC1EA,SAASyB,EAAkB1B,EAAY2B,EAASvC,EAASc,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAShC,EAATgC,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAShC,EAASc,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,EAC/C,CCnBA0B,EAAAC,EAAA,UAAAV"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 061ad6c..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From e17c6de1bf55481a6693208368d4bcfe61b30db7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jul 2023 13:42:38 +0000 Subject: [PATCH 055/147] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 798 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 47 +- benchmark/benchmark.factory.js | 73 - benchmark/benchmark.js | 160 - branches.md | 53 - docs/repl.txt | 224 - docs/types/test.ts | 166 - examples/index.js | 55 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 165 - lib/index.js | 77 - lib/limit.js | 142 - lib/main.js | 96 - lib/validate.js | 80 - package.json | 64 +- stats.html | 6177 +++++++++++++++++++++ test/test.factory.js | 1095 ---- test/test.js | 38 - test/test.main.js | 1035 ---- test/test.validate.js | 181 - 44 files changed, 6208 insertions(+), 6809 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/limit.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index f2afca7..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-07-01T03:52:27.697Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1e08946..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 663f5df..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 45a5053..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '37 1 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 3e8e2db..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,798 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -447,7 +446,7 @@ reduceRightAsync( files, acc, read, done ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -515,11 +514,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right +[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right/tree/esm -[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce +[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/tree/esm diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 46d8b83..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var reduceRightAsync; - var arr; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - reduceRightAsync = factory( onItem ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - var acc; - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 6ad0714..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var reduceRightAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=false', function benchmark( b ) { - var opts; - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'series': false - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var arr; - var len; - var acc; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'limit': 3 - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index acfc6d6..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right" -%% click B href "https://github.com/stdlib-js/utils-async-reduce-right/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-reduce-right/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-reduce-right/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-reduce-right/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right -[production-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3f22669..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,224 +0,0 @@ - -{{alias}}( collection, initial, [options,] reducer, done ) - Applies a function against an accumulator and each element in a collection - and returns the accumulated result, iterating from right to left. - - When invoked, `reducer` is provided a maximum of five arguments: - - - `accumulator`: accumulated value - - `value`: collection value - - `index`: collection index - - `collection`: the input collection - - `next`: a callback to be invoked after processing a collection `value` - - The actual number of provided arguments depends on function length. If - `reducer` accepts three arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `next` - - If `reducer` accepts four arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `index` - - `next` - - For every other `reducer` signature, `reducer` is provided all five - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `accumulator`: accumulated value - - If a provided function calls the `next` callback with a truthy `error` - argument, the function suspends execution and immediately calls the `done` - callback for subsequent `error` handling. - - Execution is *not* guaranteed to be asynchronous. To guarantee asynchrony, - 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`). - - The function does not support dynamic collection resizing. - - If provided an empty collection, the function invokes the `done` callback - with the `initial` value as the second argument. - - The function does not skip `undefined` elements. - - When processing collection elements concurrently, *beware* of race - conditions when updating an accumulator. This is especially true when an - accumulator is a primitive (e.g., a number). In general, prefer object - accumulators. - - Parameters - ---------- - collection: Array|TypedArray|Object - Input collection over which to iterate. If provided an object, the - object must be array-like (excluding strings and functions). - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - reducer: Function - The function to invoke for each element in a collection. - - done: Function - A callback invoked either upon processing all collection elements or - upon encountering an error. - - Examples - -------- - // Basic usage: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, fcn, done ) - 3000 - 2500 - 1000 - 6500 - - // Limit number of concurrent invocations: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'limit': 2 }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 2500 - 3000 - 1000 - 6500 - - // Process concurrently: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'series': false }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 1000 - 2500 - 3000 - 6500 - - -{{alias}}.factory( [options,] fcn ) - Returns a function which applies a function against an accumulator and each - element in a collection and returns the accumulated result, iterating from - right to left. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - fcn: Function - The function to invoke for each element in a collection. - - Returns - ------- - out: Function - A function which invokes a function for each element in a collection. - - Examples - -------- - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > var opts = { 'series': false }; - > var f = {{alias}}.factory( opts, fcn ); - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > f( arr, acc, done ) - 1000 - 2500 - 3000 - 6500 - > acc = { 'sum': 0 }; - > arr = [ 1000, 1500, 2000 ]; - > f( arr, acc, done ) - 1000 - 1500 - 2000 - 4500 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 143a132..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,166 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unsafe-any */ - -import reduceRightAsync = require( './index' ); - -const reducer = ( acc: any, value: number, index: number, next: Function ) => { - acc.sum += value; - if ( index === void 0 ) { - throw new Error( '`index` is missing.' ); - } - next( null, acc ); -}; - -const done = ( error: Error | null, acc: any ) => { - if ( error ) { - throw error; - } - if ( acc === void 0 ) { - throw new Error( '`acc` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( 2, acc, reducer, done ); // $ExpectError - reduceRightAsync( false, acc, reducer, done ); // $ExpectError - reduceRightAsync( true, acc, reducer, done ); // $ExpectError - reduceRightAsync( {}, acc, reducer, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a predicate argument which is not a predicate function... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 2, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, false, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, true, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 'abc', done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, [], done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a done callback argument which is not a function having a supported signature... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 2 ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, false ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, true ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 'abc' ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, {} ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, [] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const acc = { 'sum': 0 }; - reduceRightAsync(); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, reducer, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - reduceRightAsync.factory( reducer ); // $ExpectType FactoryFunction - reduceRightAsync.factory( { 'series': true }, reducer ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - reduceRightAsync.factory( [], reducer ); // $ExpectError - reduceRightAsync.factory( 123, reducer ); // $ExpectError - reduceRightAsync.factory( 'abc', reducer ); // $ExpectError - reduceRightAsync.factory( false, reducer ); // $ExpectError - reduceRightAsync.factory( true, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not a predicate function... -{ - reduceRightAsync.factory( {} ); // $ExpectError - reduceRightAsync.factory( true ); // $ExpectError - reduceRightAsync.factory( false ); // $ExpectError - reduceRightAsync.factory( {}, 123 ); // $ExpectError - reduceRightAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1( 12, acc, done ); // $ExpectError - fcn1( true, acc, done ); // $ExpectError - fcn1( false, acc, done ); // $ExpectError - fcn1( {}, acc, done ); // $ExpectError - - fcn1( [ 3000, 2500, 1000 ], acc, 12 ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, true ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, false ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, '5' ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, {} ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, [] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1(); // $ExpectError - fcn1( [ 3000, 2500, 1000 ] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - reduceRightAsync.factory( { 'limit': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': true }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': false }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - reduceRightAsync.factory( { 'series': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': 12 }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - reduceRightAsync.factory(); // $ExpectError - reduceRightAsync.factory( {}, reducer, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index dd64345..0000000 --- a/examples/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var resolve = require( 'path' ).resolve; -var readFile = require( '@stdlib/fs-read-file' ); -var reduceRightAsync = require( './../lib' ); - -var files = [ - resolve( __dirname, '..', 'package.json' ), - resolve( __dirname, '..', 'README.md' ) -]; - -function done( error, acc ) { - if ( error ) { - throw error; - } - console.log( acc.count ); -} - -function read( acc, file, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( file, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( null, acc ); - } - acc.count += 1; - next( null, acc ); - } -} - -var acc = { - 'count': 0 -}; -reduceRightAsync( files, acc, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index b19e443..9dc0658 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { Collection } from '@stdlib/types/object'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..2270aa3 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.8-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";function m(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("0id30","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!d(e.limit))?new TypeError(r("0id3b","limit",e.limit)):null):new TypeError(r("0id2h",t))}function c(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){if(this instanceof e){var i=[null];i.push.apply(i,arguments);var r=Function.bind.apply(t,i);return new r}return t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var f=c(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function p(e,t,i,r,s){var n,o,l,d,m,c;if(d=e.length,f("Collection length: %d",d),0===d)return f("Finished processing a collection."),s(null,t);for(l=d0&&p();function p(){function s(e,i){if(!o){if(e)return o=!0,u(e);f("Accumulator: %s",JSON.stringify(i)),t=i,u()}}f("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function u(e){return e?(f("Encountered an error: %s",e.message),s(e)):(f("Processed %d of %d collection elements.",n+=1,d),m>0?p():n===d?(f("Finished processing a collection."),s(null,t)):void 0)}}function u(e,n){var o,l,d;if(o={},arguments.length>1){if(l=m(o,e))throw l;d=n}else d=e;if(!t(d))throw new TypeError(r("0id43",d));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=s),c;function c(e,s,n){if(!i(e))throw new TypeError(r("0idBO",e));if(!t(n))throw new TypeError(r("0id43",n));return p(e,s,o,d,(function(e,t){if(e)return n(e);n(null,t)}))}}function a(e,t,i,r,s){if(arguments.length<5)return u(i)(e,t,r);u(i,r)(e,t,s)}e(a,"factory",u);export{a as default,u as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..63e894f --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '0id2h', 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( '0id30', '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( '0id3b', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0id43', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '0idBO', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0id43', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\n* @param {Collection} collection - input collection\n* @param {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","logger","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly","main"],"mappings":";;u2BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUR,EAAKK,SAGnDF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASR,EAAKS,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASP,GAkBzC,8eC/CIU,uDAAQC,CAAQ,4BAkBpB,SAASH,EAAOI,EAAYC,EAAKd,EAAMe,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMP,EAAWU,OACjBZ,EAAO,wBAAyBS,GAEnB,IAARA,EAEJ,OADAT,EAAO,qCACAK,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAEZE,EAAO,wBAAyBQ,GAChCR,EAAO,0BAA2BI,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdf,EAAO,kBAAmBkB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,GAPC,CAQD,CA5BDjB,EAAO,6BADPU,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJf,EAAO,2BAA4Be,EAAMM,SAClChB,EAAMU,KAGdf,EAAO,0CADPM,GAAS,EACgDG,GACpDC,EAAM,EACHG,IAEHP,IAAUG,GACdT,EAAO,qCACAK,EAAM,KAAMF,SAFpB,EAIA,CACF,CCxCA,SAASmB,EAAShC,EAASc,GAC1B,IAAIf,EACAkC,EACAC,EAGJ,GADAnC,EAAO,CAAA,EACFoC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMnC,EAAUC,EAAMC,GAErB,MAAMiC,EAEPC,EAAIpB,CACN,MACEoB,EAAIlC,EAEL,IAAMoC,EAAYF,GACjB,MAAM,IAAI5B,UAAWC,EAAQ,QAAS2B,IAUvC,YARqB,IAAhBnC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ6B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIN,UAAWC,EAAQ,QAASK,IAEvC,IAAMwB,EAAYrB,GACjB,MAAM,IAAIT,UAAWC,EAAQ,QAASQ,IAEvC,OAAOP,EAAOI,EAAY2B,EAASxC,EAAMmC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,EACZ,GACD,CACF,CC1EA,SAASyB,EAAkB1B,EAAY2B,EAASvC,EAASc,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAShC,EAATgC,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAShC,EAASc,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,EAC/C,CCnBA0B,EAAAC,EAAA,UAAAV"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 6d67be2..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var validate = require( './validate.js' ); -var limit = require( './limit.js' ); - - -// MAIN // - -/** -* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} last argument must be a function -* @returns {Function} function which invokes the provided function once for each element in a collection -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error, data ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var opts = { -* 'series': false -* }; -* -* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: -* var reduceRightAsync = factory( opts, read ); -* -* // Create a collection over which to iterate: -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* // Define a callback which handles errors: -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* // Run `read` for each element in `files`: -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, done ); -*/ -function factory( options, fcn ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = fcn; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '0id43', f ) ); - } - if ( opts.series === void 0 && opts.limit === void 0 ) { - opts.series = true; - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return reduceRightAsync; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * @private - * @param {Collection} collection - input collection - * @param {*} initial - initial value - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be a collection - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function reduceRightAsync( collection, initial, done ) { - if ( !isCollection( collection ) ) { - throw new TypeError( format( '0idBO', collection ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '0id43', done ) ); - } - return limit( collection, initial, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {*} [acc] - accumulated value - * @returns {void} - */ - function clbk( error, acc ) { - if ( error ) { - return done( error ); - } - done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ae657ff..0000000 --- a/lib/index.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* @module @stdlib/utils-async-reduce-right -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' ); -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/limit.js b/lib/limit.js deleted file mode 100644 index cdb60af..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); - - -// VARIABLES // - -var debug = logger( 'reduce-right-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each element in a collection, limiting the number of concurrently pending functions and iterating from right to left. -* -* @private -* @param {Collection} collection - input collection -* @param {*} acc - initial value -* @param {Options} opts - function options -* @param {*} [opts.thisArg] - execution context -* @param {PositiveInteger} [opts.limit] - maximum number of pending function invocations -* @param {Function} fcn - function to invoke -* @param {Callback} done - function to invoke upon completion or upon encountering an error -* @returns {void} -*/ -function limit( collection, acc, opts, fcn, done ) { - var count; - var flg; - var lim; - var len; - var idx; - var i; - - len = collection.length; - debug( 'Collection length: %d', len ); - - if ( len === 0 ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - count = 0; - idx = len; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all collection elements... - if ( idx > 0 ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next element in a collection. - * - * @private - */ - function next() { - idx -= 1; - debug( 'Collection element %d: %s.', idx, JSON.stringify( collection[ idx ] ) ); - if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], cb ); - } else if ( fcn.length === 4 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, cb ); - } else { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len - } - /** - * Callback invoked once a provided function finishes processing a collection element. - * - * @private - * @param {*} [error] - error - * @param {*} [result] - accumulation result - * @returns {void} - */ - function cb( error, result ) { - if ( flg ) { - // Prevent further processing of collection elements: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Accumulator: %s', JSON.stringify( result ) ); - acc = result; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next collection element. - * - * @private - * @param {*} [error] - error - * @returns {void} - */ - function clbk( error ) { - if ( error ) { - debug( 'Encountered an error: %s', error.message ); - return done( error ); - } - count += 1; - debug( 'Processed %d of %d collection elements.', count, len ); - if ( idx > 0 ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 9f016bf..0000000 --- a/lib/main.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param {Collection} collection - input collection -* @param {*} initial - initial value -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} second-to-last argument must be a function -* @throws {TypeError} last argument must be a function -* @returns {void} -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -function reduceRightAsync( collection, initial, options, fcn, done ) { - if ( arguments.length < 5 ) { - return factory( options )( collection, initial, fcn ); - } - factory( options, fcn )( collection, initial, done ); -} - - -// EXPORTS // - -module.exports = reduceRightAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 6292663..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @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 -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'thisArg': {}, -* 'series': false, -* 'limit': 10 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '0id2h', options ) ); - } - if ( hasOwnProp( options, 'thisArg' ) ) { - opts.thisArg = options.thisArg; - } - if ( hasOwnProp( options, 'series' ) ) { - opts.series = options.series; - if ( !isBoolean( opts.series ) ) { - return new TypeError( format( '0id30', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '0id3b', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 8660367..cfe057f 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.8", "description": "Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,43 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.0.7", - "@stdlib/assert-is-boolean": "^0.0.8", - "@stdlib/assert-is-collection": "^0.0.8", - "@stdlib/assert-is-function": "^0.0.8", - "@stdlib/assert-is-plain-object": "^0.0.7", - "@stdlib/assert-is-positive-integer": "^0.0.7", - "@stdlib/constants-float64-pinf": "^0.0.8", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/types": "^0.0.14", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.12", - "@stdlib/constants-float64-eps": "^0.0.8", - "@stdlib/fs-read-file": "^0.0.8", - "@stdlib/utils-noop": "^0.0.14", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..e27aaf2 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 8244931..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1095 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( {}, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, next ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - factory( opts, next ); - }; - } -}); - -tape( 'the function returns a function (no options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided a collection (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a collection (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (1 argument)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (2 arguments)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with five arguments', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn() { - var value; - var next; - var acc; - var k; - - acc = arguments[ 0 ]; - value = arguments[ 1 ]; - k = arguments[ 2 ]; - next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( k, i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the returned function supports processing collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements concurrently', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 100, 250, 300 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements sequentially (limit = 1)', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of collection elements which are processed at any one time', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 250, 300, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 250, 100, 300 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var reduceRightAsync; - var arr; - - reduceRightAsync = factory( fcn ); - arr = []; - - reduceRightAsync( arr, 0, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var reduceRightAsync; - var obj; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = []; - obj = {}; - reduceRightAsync( arr, obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - i = 0; - - reduceRightAsync( arr, {}, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, acc ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the returned function does not skip empty elements', function test( t ) { - var reduceRightAsync; - var expected; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index f273a40..0000000 --- a/test/test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof reduceRightAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 1893240..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1035 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a collection', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (no options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, next, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, 0 ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - reduceRightAsync( [ 1, 2, 3 ], 0, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (1 argument)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (2 arguments)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with five arguments', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn() { - var next; - var acc; - var v; - - next = arguments[ 4 ]; - acc = arguments[ 0 ]; - v = arguments[ 1 ]; - - i -= 1; - j += 1; - - t.strictEqual( v, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, v ); - - function onTimeout() { - acc.sum += v; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'by default, the function processes collection elements sequentially', function test( t ) { - var values; - var count; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements concurrently', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 100, 250, 300 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': true - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially (limit = 1)', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var arr; - var ctx; - - arr = [ 3, 2, 1 ]; - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 3, 2, 1 ]; - opts = { - 'series': true - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 250, 100, 300 ]; - opts = { - 'limit': 2 - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var arr = []; - reduceRightAsync( arr, 0, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var arr = []; - var obj = {}; - - reduceRightAsync( arr, obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - arr = [ 3, 2, 1 ]; - i = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, value ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the function does not skip empty elements', function test( t ) { - var expected; - var arr; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, fcn, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 7660838..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,181 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `limit` option which is not a positive integer', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - -5, - 0, - 3.14, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'limit': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `series` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'series': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function accepts any value for the `thisArg` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'thisArg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err, null, 'returns null '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'thisArg': {}, - 'series': false, - 'limit': 10 - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From 0cdb43943c4c4fe5e56d58975e7a46239fcaf70b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Aug 2023 06:27:38 +0000 Subject: [PATCH 056/147] Transform error messages --- lib/factory.js | 8 ++++---- lib/validate.js | 8 ++++---- package.json | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index a627d69..6d67be2 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -22,7 +22,7 @@ var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var PINF = require( '@stdlib/constants-float64-pinf' ); var validate = require( './validate.js' ); var limit = require( './limit.js' ); @@ -110,7 +110,7 @@ function factory( options, fcn ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '0id43', f ) ); } if ( opts.series === void 0 && opts.limit === void 0 ) { opts.series = true; @@ -135,10 +135,10 @@ function factory( options, fcn ) { */ function reduceRightAsync( collection, initial, done ) { if ( !isCollection( collection ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a collection. Value: `%s`.', collection ) ); + throw new TypeError( format( '0idBO', collection ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '0id43', done ) ); } return limit( collection, initial, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index 9ba927e..6292663 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,7 +54,7 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0id2h', options ) ); } if ( hasOwnProp( options, 'thisArg' ) ) { opts.thisArg = options.thisArg; @@ -62,13 +62,13 @@ function validate( opts, options ) { if ( hasOwnProp( options, 'series' ) ) { opts.series = options.series; if ( !isBoolean( opts.series ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'series', opts.series ) ); + return new TypeError( format( '0id30', 'series', opts.series ) ); } } if ( hasOwnProp( options, 'limit' ) ) { opts.limit = options.limit; if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'limit', opts.limit ) ); + return new TypeError( format( '0id3b', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index e0057f8..8660367 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-plain-object": "^0.0.7", "@stdlib/assert-is-positive-integer": "^0.0.7", "@stdlib/constants-float64-pinf": "^0.0.8", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/types": "^0.0.14", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7", "debug": "^2.6.9" From 63536f858a6dde9f1a5eb41ccfb808d5d781cccd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Aug 2023 14:50:31 +0000 Subject: [PATCH 057/147] Remove files --- index.d.ts | 415 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6597 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 9dc0658..0000000 --- a/index.d.ts +++ /dev/null @@ -1,415 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Collection } from '@stdlib/types/object'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * The maximum number of pending invocations at any one time. - */ - limit?: number; - - /** - * Boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection (default: true). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback function. -*/ -type Nullary = () => void; - -/** -* Callback function. -* -* @param error - encountered error or null -*/ -type Unary = ( error: Error | null ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Binary = ( error: Error | null, accumulator: any ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param next - a callback to be invoked after processing a collection `value` -*/ -type TernaryReducer = ( accumulator: any, value: any, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuaternaryReducer = ( accumulator: any, value: any, index: number, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuinaryReducer = ( accumulator: any, value: any, index: number, collection: Collection, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type Reducer = TernaryReducer | QuaternaryReducer | QuinaryReducer; - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result. -* -* @param collection - input collection -* @param initial - initial value -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( collection: Collection, initial: any, done: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Interface for `reduceRightAsync`. -*/ -interface ReduceRightAsync { - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, {}, read, done ); - */ - ( collection: Collection, initial: any, options: Options, reducer: Reducer, done: Callback ): void; // tslint-disable-line max-line-length - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, read, done ); - */ - ( collection: Collection, initial: any, reducer: Reducer, done: Callback ): void; // tslint-disable-line max-line-length - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @throws must provide valid options - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var opts = { - * 'series': false - * }; - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( opts, read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( options: Options, reducer: Reducer ): FactoryFunction; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param reducer - function to invoke for each element in a collection - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( reducer: Reducer ): FactoryFunction; -} - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param collection - input collection -* @param initial - initial value -* @param options - function options -* @param options.thisArg - execution context -* @param options.limit - maximum number of pending invocations at any one time -* @param 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 (default: true) -* @param reducer - function to invoke for each element in a collection -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( `@stdlib/fs/read-file` ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -declare var reduceRightAsync: ReduceRightAsync; - - -// EXPORTS // - -export = reduceRightAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 2270aa3..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.8-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";function m(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("0id30","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!d(e.limit))?new TypeError(r("0id3b","limit",e.limit)):null):new TypeError(r("0id2h",t))}function c(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){if(this instanceof e){var i=[null];i.push.apply(i,arguments);var r=Function.bind.apply(t,i);return new r}return t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var f=c(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function p(e,t,i,r,s){var n,o,l,d,m,c;if(d=e.length,f("Collection length: %d",d),0===d)return f("Finished processing a collection."),s(null,t);for(l=d0&&p();function p(){function s(e,i){if(!o){if(e)return o=!0,u(e);f("Accumulator: %s",JSON.stringify(i)),t=i,u()}}f("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function u(e){return e?(f("Encountered an error: %s",e.message),s(e)):(f("Processed %d of %d collection elements.",n+=1,d),m>0?p():n===d?(f("Finished processing a collection."),s(null,t)):void 0)}}function u(e,n){var o,l,d;if(o={},arguments.length>1){if(l=m(o,e))throw l;d=n}else d=e;if(!t(d))throw new TypeError(r("0id43",d));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=s),c;function c(e,s,n){if(!i(e))throw new TypeError(r("0idBO",e));if(!t(n))throw new TypeError(r("0id43",n));return p(e,s,o,d,(function(e,t){if(e)return n(e);n(null,t)}))}}function a(e,t,i,r,s){if(arguments.length<5)return u(i)(e,t,r);u(i,r)(e,t,s)}e(a,"factory",u);export{a as default,u as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 63e894f..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '0id2h', 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( '0id30', '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( '0id3b', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0id43', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '0idBO', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0id43', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\n* @param {Collection} collection - input collection\n* @param {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","logger","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly","main"],"mappings":";;u2BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUR,EAAKK,SAGnDF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASR,EAAKS,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASP,GAkBzC,8eC/CIU,uDAAQC,CAAQ,4BAkBpB,SAASH,EAAOI,EAAYC,EAAKd,EAAMe,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMP,EAAWU,OACjBZ,EAAO,wBAAyBS,GAEnB,IAARA,EAEJ,OADAT,EAAO,qCACAK,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAEZE,EAAO,wBAAyBQ,GAChCR,EAAO,0BAA2BI,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdf,EAAO,kBAAmBkB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,GAPC,CAQD,CA5BDjB,EAAO,6BADPU,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJf,EAAO,2BAA4Be,EAAMM,SAClChB,EAAMU,KAGdf,EAAO,0CADPM,GAAS,EACgDG,GACpDC,EAAM,EACHG,IAEHP,IAAUG,GACdT,EAAO,qCACAK,EAAM,KAAMF,SAFpB,EAIA,CACF,CCxCA,SAASmB,EAAShC,EAASc,GAC1B,IAAIf,EACAkC,EACAC,EAGJ,GADAnC,EAAO,CAAA,EACFoC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMnC,EAAUC,EAAMC,GAErB,MAAMiC,EAEPC,EAAIpB,CACN,MACEoB,EAAIlC,EAEL,IAAMoC,EAAYF,GACjB,MAAM,IAAI5B,UAAWC,EAAQ,QAAS2B,IAUvC,YARqB,IAAhBnC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ6B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIN,UAAWC,EAAQ,QAASK,IAEvC,IAAMwB,EAAYrB,GACjB,MAAM,IAAIT,UAAWC,EAAQ,QAASQ,IAEvC,OAAOP,EAAOI,EAAY2B,EAASxC,EAAMmC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,EACZ,GACD,CACF,CC1EA,SAASyB,EAAkB1B,EAAY2B,EAASvC,EAASc,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAShC,EAATgC,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAShC,EAASc,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,EAC/C,CCnBA0B,EAAAC,EAAA,UAAAV"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index e27aaf2..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From ca661b3986165f1050b3a732b3d27ee390629ea7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Aug 2023 14:51:10 +0000 Subject: [PATCH 058/147] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 798 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 47 +- benchmark/benchmark.factory.js | 73 - benchmark/benchmark.js | 160 - branches.md | 53 - docs/repl.txt | 224 - docs/types/test.ts | 166 - examples/index.js | 55 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 165 - lib/index.js | 77 - lib/limit.js | 142 - lib/main.js | 96 - lib/validate.js | 80 - package.json | 64 +- stats.html | 6177 +++++++++++++++++++++ test/test.factory.js | 1095 ---- test/test.js | 38 - test/test.main.js | 1035 ---- test/test.validate.js | 181 - 44 files changed, 6208 insertions(+), 6809 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/limit.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 938fe4d..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-08-01T04:15:21.176Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1e08946..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 663f5df..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 45a5053..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '37 1 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 334eb59..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,798 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -447,7 +446,7 @@ reduceRightAsync( files, acc, read, done ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -515,11 +514,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right +[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right/tree/esm -[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce +[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/tree/esm diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 46d8b83..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var reduceRightAsync; - var arr; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - reduceRightAsync = factory( onItem ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - var acc; - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 6ad0714..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var reduceRightAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=false', function benchmark( b ) { - var opts; - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'series': false - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var arr; - var len; - var acc; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'limit': 3 - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index acfc6d6..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right" -%% click B href "https://github.com/stdlib-js/utils-async-reduce-right/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-reduce-right/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-reduce-right/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-reduce-right/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right -[production-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3f22669..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,224 +0,0 @@ - -{{alias}}( collection, initial, [options,] reducer, done ) - Applies a function against an accumulator and each element in a collection - and returns the accumulated result, iterating from right to left. - - When invoked, `reducer` is provided a maximum of five arguments: - - - `accumulator`: accumulated value - - `value`: collection value - - `index`: collection index - - `collection`: the input collection - - `next`: a callback to be invoked after processing a collection `value` - - The actual number of provided arguments depends on function length. If - `reducer` accepts three arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `next` - - If `reducer` accepts four arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `index` - - `next` - - For every other `reducer` signature, `reducer` is provided all five - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `accumulator`: accumulated value - - If a provided function calls the `next` callback with a truthy `error` - argument, the function suspends execution and immediately calls the `done` - callback for subsequent `error` handling. - - Execution is *not* guaranteed to be asynchronous. To guarantee asynchrony, - 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`). - - The function does not support dynamic collection resizing. - - If provided an empty collection, the function invokes the `done` callback - with the `initial` value as the second argument. - - The function does not skip `undefined` elements. - - When processing collection elements concurrently, *beware* of race - conditions when updating an accumulator. This is especially true when an - accumulator is a primitive (e.g., a number). In general, prefer object - accumulators. - - Parameters - ---------- - collection: Array|TypedArray|Object - Input collection over which to iterate. If provided an object, the - object must be array-like (excluding strings and functions). - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - reducer: Function - The function to invoke for each element in a collection. - - done: Function - A callback invoked either upon processing all collection elements or - upon encountering an error. - - Examples - -------- - // Basic usage: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, fcn, done ) - 3000 - 2500 - 1000 - 6500 - - // Limit number of concurrent invocations: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'limit': 2 }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 2500 - 3000 - 1000 - 6500 - - // Process concurrently: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'series': false }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 1000 - 2500 - 3000 - 6500 - - -{{alias}}.factory( [options,] fcn ) - Returns a function which applies a function against an accumulator and each - element in a collection and returns the accumulated result, iterating from - right to left. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - fcn: Function - The function to invoke for each element in a collection. - - Returns - ------- - out: Function - A function which invokes a function for each element in a collection. - - Examples - -------- - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > var opts = { 'series': false }; - > var f = {{alias}}.factory( opts, fcn ); - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > f( arr, acc, done ) - 1000 - 2500 - 3000 - 6500 - > acc = { 'sum': 0 }; - > arr = [ 1000, 1500, 2000 ]; - > f( arr, acc, done ) - 1000 - 1500 - 2000 - 4500 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 143a132..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,166 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unsafe-any */ - -import reduceRightAsync = require( './index' ); - -const reducer = ( acc: any, value: number, index: number, next: Function ) => { - acc.sum += value; - if ( index === void 0 ) { - throw new Error( '`index` is missing.' ); - } - next( null, acc ); -}; - -const done = ( error: Error | null, acc: any ) => { - if ( error ) { - throw error; - } - if ( acc === void 0 ) { - throw new Error( '`acc` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( 2, acc, reducer, done ); // $ExpectError - reduceRightAsync( false, acc, reducer, done ); // $ExpectError - reduceRightAsync( true, acc, reducer, done ); // $ExpectError - reduceRightAsync( {}, acc, reducer, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a predicate argument which is not a predicate function... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 2, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, false, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, true, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 'abc', done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, [], done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a done callback argument which is not a function having a supported signature... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 2 ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, false ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, true ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 'abc' ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, {} ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, [] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const acc = { 'sum': 0 }; - reduceRightAsync(); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, reducer, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - reduceRightAsync.factory( reducer ); // $ExpectType FactoryFunction - reduceRightAsync.factory( { 'series': true }, reducer ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - reduceRightAsync.factory( [], reducer ); // $ExpectError - reduceRightAsync.factory( 123, reducer ); // $ExpectError - reduceRightAsync.factory( 'abc', reducer ); // $ExpectError - reduceRightAsync.factory( false, reducer ); // $ExpectError - reduceRightAsync.factory( true, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not a predicate function... -{ - reduceRightAsync.factory( {} ); // $ExpectError - reduceRightAsync.factory( true ); // $ExpectError - reduceRightAsync.factory( false ); // $ExpectError - reduceRightAsync.factory( {}, 123 ); // $ExpectError - reduceRightAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1( 12, acc, done ); // $ExpectError - fcn1( true, acc, done ); // $ExpectError - fcn1( false, acc, done ); // $ExpectError - fcn1( {}, acc, done ); // $ExpectError - - fcn1( [ 3000, 2500, 1000 ], acc, 12 ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, true ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, false ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, '5' ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, {} ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, [] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1(); // $ExpectError - fcn1( [ 3000, 2500, 1000 ] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - reduceRightAsync.factory( { 'limit': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': true }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': false }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - reduceRightAsync.factory( { 'series': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': 12 }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - reduceRightAsync.factory(); // $ExpectError - reduceRightAsync.factory( {}, reducer, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index dd64345..0000000 --- a/examples/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var resolve = require( 'path' ).resolve; -var readFile = require( '@stdlib/fs-read-file' ); -var reduceRightAsync = require( './../lib' ); - -var files = [ - resolve( __dirname, '..', 'package.json' ), - resolve( __dirname, '..', 'README.md' ) -]; - -function done( error, acc ) { - if ( error ) { - throw error; - } - console.log( acc.count ); -} - -function read( acc, file, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( file, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( null, acc ); - } - acc.count += 1; - next( null, acc ); - } -} - -var acc = { - 'count': 0 -}; -reduceRightAsync( files, acc, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index b19e443..9dc0658 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { Collection } from '@stdlib/types/object'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..2270aa3 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.8-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";function m(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("0id30","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!d(e.limit))?new TypeError(r("0id3b","limit",e.limit)):null):new TypeError(r("0id2h",t))}function c(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){if(this instanceof e){var i=[null];i.push.apply(i,arguments);var r=Function.bind.apply(t,i);return new r}return t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var f=c(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function p(e,t,i,r,s){var n,o,l,d,m,c;if(d=e.length,f("Collection length: %d",d),0===d)return f("Finished processing a collection."),s(null,t);for(l=d0&&p();function p(){function s(e,i){if(!o){if(e)return o=!0,u(e);f("Accumulator: %s",JSON.stringify(i)),t=i,u()}}f("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function u(e){return e?(f("Encountered an error: %s",e.message),s(e)):(f("Processed %d of %d collection elements.",n+=1,d),m>0?p():n===d?(f("Finished processing a collection."),s(null,t)):void 0)}}function u(e,n){var o,l,d;if(o={},arguments.length>1){if(l=m(o,e))throw l;d=n}else d=e;if(!t(d))throw new TypeError(r("0id43",d));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=s),c;function c(e,s,n){if(!i(e))throw new TypeError(r("0idBO",e));if(!t(n))throw new TypeError(r("0id43",n));return p(e,s,o,d,(function(e,t){if(e)return n(e);n(null,t)}))}}function a(e,t,i,r,s){if(arguments.length<5)return u(i)(e,t,r);u(i,r)(e,t,s)}e(a,"factory",u);export{a as default,u as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..63e894f --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '0id2h', 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( '0id30', '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( '0id3b', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0id43', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '0idBO', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0id43', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\n* @param {Collection} collection - input collection\n* @param {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","logger","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly","main"],"mappings":";;u2BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUR,EAAKK,SAGnDF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASR,EAAKS,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASP,GAkBzC,8eC/CIU,uDAAQC,CAAQ,4BAkBpB,SAASH,EAAOI,EAAYC,EAAKd,EAAMe,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMP,EAAWU,OACjBZ,EAAO,wBAAyBS,GAEnB,IAARA,EAEJ,OADAT,EAAO,qCACAK,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAEZE,EAAO,wBAAyBQ,GAChCR,EAAO,0BAA2BI,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdf,EAAO,kBAAmBkB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,GAPC,CAQD,CA5BDjB,EAAO,6BADPU,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJf,EAAO,2BAA4Be,EAAMM,SAClChB,EAAMU,KAGdf,EAAO,0CADPM,GAAS,EACgDG,GACpDC,EAAM,EACHG,IAEHP,IAAUG,GACdT,EAAO,qCACAK,EAAM,KAAMF,SAFpB,EAIA,CACF,CCxCA,SAASmB,EAAShC,EAASc,GAC1B,IAAIf,EACAkC,EACAC,EAGJ,GADAnC,EAAO,CAAA,EACFoC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMnC,EAAUC,EAAMC,GAErB,MAAMiC,EAEPC,EAAIpB,CACN,MACEoB,EAAIlC,EAEL,IAAMoC,EAAYF,GACjB,MAAM,IAAI5B,UAAWC,EAAQ,QAAS2B,IAUvC,YARqB,IAAhBnC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ6B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIN,UAAWC,EAAQ,QAASK,IAEvC,IAAMwB,EAAYrB,GACjB,MAAM,IAAIT,UAAWC,EAAQ,QAASQ,IAEvC,OAAOP,EAAOI,EAAY2B,EAASxC,EAAMmC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,EACZ,GACD,CACF,CC1EA,SAASyB,EAAkB1B,EAAY2B,EAASvC,EAASc,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAShC,EAATgC,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAShC,EAASc,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,EAC/C,CCnBA0B,EAAAC,EAAA,UAAAV"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 6d67be2..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var validate = require( './validate.js' ); -var limit = require( './limit.js' ); - - -// MAIN // - -/** -* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} last argument must be a function -* @returns {Function} function which invokes the provided function once for each element in a collection -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error, data ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var opts = { -* 'series': false -* }; -* -* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: -* var reduceRightAsync = factory( opts, read ); -* -* // Create a collection over which to iterate: -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* // Define a callback which handles errors: -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* // Run `read` for each element in `files`: -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, done ); -*/ -function factory( options, fcn ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = fcn; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '0id43', f ) ); - } - if ( opts.series === void 0 && opts.limit === void 0 ) { - opts.series = true; - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return reduceRightAsync; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * @private - * @param {Collection} collection - input collection - * @param {*} initial - initial value - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be a collection - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function reduceRightAsync( collection, initial, done ) { - if ( !isCollection( collection ) ) { - throw new TypeError( format( '0idBO', collection ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '0id43', done ) ); - } - return limit( collection, initial, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {*} [acc] - accumulated value - * @returns {void} - */ - function clbk( error, acc ) { - if ( error ) { - return done( error ); - } - done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ae657ff..0000000 --- a/lib/index.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* @module @stdlib/utils-async-reduce-right -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' ); -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/limit.js b/lib/limit.js deleted file mode 100644 index cdb60af..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); - - -// VARIABLES // - -var debug = logger( 'reduce-right-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each element in a collection, limiting the number of concurrently pending functions and iterating from right to left. -* -* @private -* @param {Collection} collection - input collection -* @param {*} acc - initial value -* @param {Options} opts - function options -* @param {*} [opts.thisArg] - execution context -* @param {PositiveInteger} [opts.limit] - maximum number of pending function invocations -* @param {Function} fcn - function to invoke -* @param {Callback} done - function to invoke upon completion or upon encountering an error -* @returns {void} -*/ -function limit( collection, acc, opts, fcn, done ) { - var count; - var flg; - var lim; - var len; - var idx; - var i; - - len = collection.length; - debug( 'Collection length: %d', len ); - - if ( len === 0 ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - count = 0; - idx = len; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all collection elements... - if ( idx > 0 ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next element in a collection. - * - * @private - */ - function next() { - idx -= 1; - debug( 'Collection element %d: %s.', idx, JSON.stringify( collection[ idx ] ) ); - if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], cb ); - } else if ( fcn.length === 4 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, cb ); - } else { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len - } - /** - * Callback invoked once a provided function finishes processing a collection element. - * - * @private - * @param {*} [error] - error - * @param {*} [result] - accumulation result - * @returns {void} - */ - function cb( error, result ) { - if ( flg ) { - // Prevent further processing of collection elements: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Accumulator: %s', JSON.stringify( result ) ); - acc = result; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next collection element. - * - * @private - * @param {*} [error] - error - * @returns {void} - */ - function clbk( error ) { - if ( error ) { - debug( 'Encountered an error: %s', error.message ); - return done( error ); - } - count += 1; - debug( 'Processed %d of %d collection elements.', count, len ); - if ( idx > 0 ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 9f016bf..0000000 --- a/lib/main.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param {Collection} collection - input collection -* @param {*} initial - initial value -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} second-to-last argument must be a function -* @throws {TypeError} last argument must be a function -* @returns {void} -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -function reduceRightAsync( collection, initial, options, fcn, done ) { - if ( arguments.length < 5 ) { - return factory( options )( collection, initial, fcn ); - } - factory( options, fcn )( collection, initial, done ); -} - - -// EXPORTS // - -module.exports = reduceRightAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 6292663..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @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 -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'thisArg': {}, -* 'series': false, -* 'limit': 10 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '0id2h', options ) ); - } - if ( hasOwnProp( options, 'thisArg' ) ) { - opts.thisArg = options.thisArg; - } - if ( hasOwnProp( options, 'series' ) ) { - opts.series = options.series; - if ( !isBoolean( opts.series ) ) { - return new TypeError( format( '0id30', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '0id3b', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 8660367..cfe057f 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.8", "description": "Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,43 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.0.7", - "@stdlib/assert-is-boolean": "^0.0.8", - "@stdlib/assert-is-collection": "^0.0.8", - "@stdlib/assert-is-function": "^0.0.8", - "@stdlib/assert-is-plain-object": "^0.0.7", - "@stdlib/assert-is-positive-integer": "^0.0.7", - "@stdlib/constants-float64-pinf": "^0.0.8", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/types": "^0.0.14", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.12", - "@stdlib/constants-float64-eps": "^0.0.8", - "@stdlib/fs-read-file": "^0.0.8", - "@stdlib/utils-noop": "^0.0.14", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..5abdb16 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 8244931..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1095 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( {}, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, next ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - factory( opts, next ); - }; - } -}); - -tape( 'the function returns a function (no options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided a collection (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a collection (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (1 argument)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (2 arguments)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with five arguments', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn() { - var value; - var next; - var acc; - var k; - - acc = arguments[ 0 ]; - value = arguments[ 1 ]; - k = arguments[ 2 ]; - next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( k, i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the returned function supports processing collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements concurrently', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 100, 250, 300 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements sequentially (limit = 1)', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of collection elements which are processed at any one time', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 250, 300, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 250, 100, 300 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var reduceRightAsync; - var arr; - - reduceRightAsync = factory( fcn ); - arr = []; - - reduceRightAsync( arr, 0, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var reduceRightAsync; - var obj; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = []; - obj = {}; - reduceRightAsync( arr, obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - i = 0; - - reduceRightAsync( arr, {}, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, acc ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the returned function does not skip empty elements', function test( t ) { - var reduceRightAsync; - var expected; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index f273a40..0000000 --- a/test/test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof reduceRightAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 1893240..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1035 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a collection', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (no options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, next, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, 0 ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - reduceRightAsync( [ 1, 2, 3 ], 0, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (1 argument)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (2 arguments)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with five arguments', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn() { - var next; - var acc; - var v; - - next = arguments[ 4 ]; - acc = arguments[ 0 ]; - v = arguments[ 1 ]; - - i -= 1; - j += 1; - - t.strictEqual( v, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, v ); - - function onTimeout() { - acc.sum += v; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'by default, the function processes collection elements sequentially', function test( t ) { - var values; - var count; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements concurrently', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 100, 250, 300 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': true - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially (limit = 1)', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var arr; - var ctx; - - arr = [ 3, 2, 1 ]; - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 3, 2, 1 ]; - opts = { - 'series': true - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 250, 100, 300 ]; - opts = { - 'limit': 2 - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var arr = []; - reduceRightAsync( arr, 0, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var arr = []; - var obj = {}; - - reduceRightAsync( arr, obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - arr = [ 3, 2, 1 ]; - i = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, value ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the function does not skip empty elements', function test( t ) { - var expected; - var arr; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, fcn, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 7660838..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,181 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `limit` option which is not a positive integer', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - -5, - 0, - 3.14, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'limit': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `series` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'series': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function accepts any value for the `thisArg` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'thisArg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err, null, 'returns null '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'thisArg': {}, - 'series': false, - 'limit': 10 - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From 244d5d36792d00b49d0d646c28c3ad0801d84290 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 2 Aug 2023 16:47:55 +0000 Subject: [PATCH 059/147] Transform error messages --- lib/factory.js | 8 ++++---- lib/validate.js | 8 ++++---- package.json | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 1125052..f9448f7 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -22,7 +22,7 @@ var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var PINF = require( '@stdlib/constants-float64-pinf' ); var validate = require( './validate.js' ); var limit = require( './limit.js' ); @@ -109,7 +109,7 @@ function factory( options, fcn ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '0id43', f ) ); } if ( opts.series === void 0 && opts.limit === void 0 ) { opts.series = true; @@ -134,10 +134,10 @@ function factory( options, fcn ) { */ function reduceRightAsync( collection, initial, done ) { if ( !isCollection( collection ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a collection. Value: `%s`.', collection ) ); + throw new TypeError( format( '0idBO', collection ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '0id43', done ) ); } return limit( collection, initial, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index 9ba927e..6292663 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,7 +54,7 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0id2h', options ) ); } if ( hasOwnProp( options, 'thisArg' ) ) { opts.thisArg = options.thisArg; @@ -62,13 +62,13 @@ function validate( opts, options ) { if ( hasOwnProp( options, 'series' ) ) { opts.series = options.series; if ( !isBoolean( opts.series ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'series', opts.series ) ); + return new TypeError( format( '0id30', 'series', opts.series ) ); } } if ( hasOwnProp( options, 'limit' ) ) { opts.limit = options.limit; if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'limit', opts.limit ) ); + return new TypeError( format( '0id3b', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index e0057f8..8660367 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-plain-object": "^0.0.7", "@stdlib/assert-is-positive-integer": "^0.0.7", "@stdlib/constants-float64-pinf": "^0.0.8", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/types": "^0.0.14", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7", "debug": "^2.6.9" From 9844989f3beb0afcfa7d5b719d6dcfbe5c29b570 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 2 Aug 2023 16:52:43 +0000 Subject: [PATCH 060/147] Remove files --- index.d.ts | 415 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6597 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 9dc0658..0000000 --- a/index.d.ts +++ /dev/null @@ -1,415 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Collection } from '@stdlib/types/object'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * The maximum number of pending invocations at any one time. - */ - limit?: number; - - /** - * Boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection (default: true). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback function. -*/ -type Nullary = () => void; - -/** -* Callback function. -* -* @param error - encountered error or null -*/ -type Unary = ( error: Error | null ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Binary = ( error: Error | null, accumulator: any ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param next - a callback to be invoked after processing a collection `value` -*/ -type TernaryReducer = ( accumulator: any, value: any, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuaternaryReducer = ( accumulator: any, value: any, index: number, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuinaryReducer = ( accumulator: any, value: any, index: number, collection: Collection, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type Reducer = TernaryReducer | QuaternaryReducer | QuinaryReducer; - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result. -* -* @param collection - input collection -* @param initial - initial value -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( collection: Collection, initial: any, done: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Interface for `reduceRightAsync`. -*/ -interface ReduceRightAsync { - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, {}, read, done ); - */ - ( collection: Collection, initial: any, options: Options, reducer: Reducer, done: Callback ): void; // tslint-disable-line max-line-length - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, read, done ); - */ - ( collection: Collection, initial: any, reducer: Reducer, done: Callback ): void; // tslint-disable-line max-line-length - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @throws must provide valid options - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var opts = { - * 'series': false - * }; - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( opts, read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( options: Options, reducer: Reducer ): FactoryFunction; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param reducer - function to invoke for each element in a collection - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( reducer: Reducer ): FactoryFunction; -} - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param collection - input collection -* @param initial - initial value -* @param options - function options -* @param options.thisArg - execution context -* @param options.limit - maximum number of pending invocations at any one time -* @param 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 (default: true) -* @param reducer - function to invoke for each element in a collection -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( `@stdlib/fs/read-file` ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -declare var reduceRightAsync: ReduceRightAsync; - - -// EXPORTS // - -export = reduceRightAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 2270aa3..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.8-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";function m(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("0id30","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!d(e.limit))?new TypeError(r("0id3b","limit",e.limit)):null):new TypeError(r("0id2h",t))}function c(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){if(this instanceof e){var i=[null];i.push.apply(i,arguments);var r=Function.bind.apply(t,i);return new r}return t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var f=c(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function p(e,t,i,r,s){var n,o,l,d,m,c;if(d=e.length,f("Collection length: %d",d),0===d)return f("Finished processing a collection."),s(null,t);for(l=d0&&p();function p(){function s(e,i){if(!o){if(e)return o=!0,u(e);f("Accumulator: %s",JSON.stringify(i)),t=i,u()}}f("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function u(e){return e?(f("Encountered an error: %s",e.message),s(e)):(f("Processed %d of %d collection elements.",n+=1,d),m>0?p():n===d?(f("Finished processing a collection."),s(null,t)):void 0)}}function u(e,n){var o,l,d;if(o={},arguments.length>1){if(l=m(o,e))throw l;d=n}else d=e;if(!t(d))throw new TypeError(r("0id43",d));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=s),c;function c(e,s,n){if(!i(e))throw new TypeError(r("0idBO",e));if(!t(n))throw new TypeError(r("0id43",n));return p(e,s,o,d,(function(e,t){if(e)return n(e);n(null,t)}))}}function a(e,t,i,r,s){if(arguments.length<5)return u(i)(e,t,r);u(i,r)(e,t,s)}e(a,"factory",u);export{a as default,u as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 63e894f..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '0id2h', 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( '0id30', '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( '0id3b', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0id43', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '0idBO', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0id43', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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*\n* @param {Collection} collection - input collection\n* @param {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","logger","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly","main"],"mappings":";;u2BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUR,EAAKK,SAGnDF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASR,EAAKS,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASP,GAkBzC,8eC/CIU,uDAAQC,CAAQ,4BAkBpB,SAASH,EAAOI,EAAYC,EAAKd,EAAMe,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMP,EAAWU,OACjBZ,EAAO,wBAAyBS,GAEnB,IAARA,EAEJ,OADAT,EAAO,qCACAK,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAEZE,EAAO,wBAAyBQ,GAChCR,EAAO,0BAA2BI,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdf,EAAO,kBAAmBkB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,GAPC,CAQD,CA5BDjB,EAAO,6BADPU,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJf,EAAO,2BAA4Be,EAAMM,SAClChB,EAAMU,KAGdf,EAAO,0CADPM,GAAS,EACgDG,GACpDC,EAAM,EACHG,IAEHP,IAAUG,GACdT,EAAO,qCACAK,EAAM,KAAMF,SAFpB,EAIA,CACF,CCxCA,SAASmB,EAAShC,EAASc,GAC1B,IAAIf,EACAkC,EACAC,EAGJ,GADAnC,EAAO,CAAA,EACFoC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMnC,EAAUC,EAAMC,GAErB,MAAMiC,EAEPC,EAAIpB,CACN,MACEoB,EAAIlC,EAEL,IAAMoC,EAAYF,GACjB,MAAM,IAAI5B,UAAWC,EAAQ,QAAS2B,IAUvC,YARqB,IAAhBnC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ6B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIN,UAAWC,EAAQ,QAASK,IAEvC,IAAMwB,EAAYrB,GACjB,MAAM,IAAIT,UAAWC,EAAQ,QAASQ,IAEvC,OAAOP,EAAOI,EAAY2B,EAASxC,EAAMmC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,EACZ,GACD,CACF,CC1EA,SAASyB,EAAkB1B,EAAY2B,EAASvC,EAASc,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAShC,EAATgC,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAShC,EAASc,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,EAC/C,CCnBA0B,EAAAC,EAAA,UAAAV"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 5abdb16..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 44dadaa146df3a7a402ee323a6915708c3e4b6cf Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 2 Aug 2023 16:53:23 +0000 Subject: [PATCH 061/147] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 798 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 47 +- benchmark/benchmark.factory.js | 73 - benchmark/benchmark.js | 160 - branches.md | 53 - docs/repl.txt | 224 - docs/types/test.ts | 166 - examples/index.js | 55 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 164 - lib/index.js | 77 - lib/limit.js | 142 - lib/main.js | 95 - lib/validate.js | 80 - package.json | 64 +- stats.html | 6177 +++++++++++++++++++++ test/test.factory.js | 1095 ---- test/test.js | 38 - test/test.main.js | 1035 ---- test/test.validate.js | 181 - 43 files changed, 6208 insertions(+), 6806 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/limit.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1e08946..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 663f5df..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 45a5053..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '37 1 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 334eb59..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,798 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -447,7 +446,7 @@ reduceRightAsync( files, acc, read, done ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -515,11 +514,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right +[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right/tree/esm -[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce +[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/tree/esm diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 46d8b83..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var reduceRightAsync; - var arr; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - reduceRightAsync = factory( onItem ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - var acc; - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 6ad0714..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var reduceRightAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=false', function benchmark( b ) { - var opts; - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'series': false - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var arr; - var len; - var acc; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'limit': 3 - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index acfc6d6..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right" -%% click B href "https://github.com/stdlib-js/utils-async-reduce-right/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-reduce-right/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-reduce-right/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-reduce-right/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right -[production-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3f22669..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,224 +0,0 @@ - -{{alias}}( collection, initial, [options,] reducer, done ) - Applies a function against an accumulator and each element in a collection - and returns the accumulated result, iterating from right to left. - - When invoked, `reducer` is provided a maximum of five arguments: - - - `accumulator`: accumulated value - - `value`: collection value - - `index`: collection index - - `collection`: the input collection - - `next`: a callback to be invoked after processing a collection `value` - - The actual number of provided arguments depends on function length. If - `reducer` accepts three arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `next` - - If `reducer` accepts four arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `index` - - `next` - - For every other `reducer` signature, `reducer` is provided all five - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `accumulator`: accumulated value - - If a provided function calls the `next` callback with a truthy `error` - argument, the function suspends execution and immediately calls the `done` - callback for subsequent `error` handling. - - Execution is *not* guaranteed to be asynchronous. To guarantee asynchrony, - 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`). - - The function does not support dynamic collection resizing. - - If provided an empty collection, the function invokes the `done` callback - with the `initial` value as the second argument. - - The function does not skip `undefined` elements. - - When processing collection elements concurrently, *beware* of race - conditions when updating an accumulator. This is especially true when an - accumulator is a primitive (e.g., a number). In general, prefer object - accumulators. - - Parameters - ---------- - collection: Array|TypedArray|Object - Input collection over which to iterate. If provided an object, the - object must be array-like (excluding strings and functions). - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - reducer: Function - The function to invoke for each element in a collection. - - done: Function - A callback invoked either upon processing all collection elements or - upon encountering an error. - - Examples - -------- - // Basic usage: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, fcn, done ) - 3000 - 2500 - 1000 - 6500 - - // Limit number of concurrent invocations: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'limit': 2 }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 2500 - 3000 - 1000 - 6500 - - // Process concurrently: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'series': false }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 1000 - 2500 - 3000 - 6500 - - -{{alias}}.factory( [options,] fcn ) - Returns a function which applies a function against an accumulator and each - element in a collection and returns the accumulated result, iterating from - right to left. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - fcn: Function - The function to invoke for each element in a collection. - - Returns - ------- - out: Function - A function which invokes a function for each element in a collection. - - Examples - -------- - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > var opts = { 'series': false }; - > var f = {{alias}}.factory( opts, fcn ); - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > f( arr, acc, done ) - 1000 - 2500 - 3000 - 6500 - > acc = { 'sum': 0 }; - > arr = [ 1000, 1500, 2000 ]; - > f( arr, acc, done ) - 1000 - 1500 - 2000 - 4500 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 143a132..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,166 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unsafe-any */ - -import reduceRightAsync = require( './index' ); - -const reducer = ( acc: any, value: number, index: number, next: Function ) => { - acc.sum += value; - if ( index === void 0 ) { - throw new Error( '`index` is missing.' ); - } - next( null, acc ); -}; - -const done = ( error: Error | null, acc: any ) => { - if ( error ) { - throw error; - } - if ( acc === void 0 ) { - throw new Error( '`acc` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( 2, acc, reducer, done ); // $ExpectError - reduceRightAsync( false, acc, reducer, done ); // $ExpectError - reduceRightAsync( true, acc, reducer, done ); // $ExpectError - reduceRightAsync( {}, acc, reducer, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a predicate argument which is not a predicate function... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 2, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, false, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, true, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 'abc', done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, [], done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a done callback argument which is not a function having a supported signature... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 2 ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, false ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, true ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 'abc' ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, {} ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, [] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const acc = { 'sum': 0 }; - reduceRightAsync(); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, reducer, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - reduceRightAsync.factory( reducer ); // $ExpectType FactoryFunction - reduceRightAsync.factory( { 'series': true }, reducer ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - reduceRightAsync.factory( [], reducer ); // $ExpectError - reduceRightAsync.factory( 123, reducer ); // $ExpectError - reduceRightAsync.factory( 'abc', reducer ); // $ExpectError - reduceRightAsync.factory( false, reducer ); // $ExpectError - reduceRightAsync.factory( true, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not a predicate function... -{ - reduceRightAsync.factory( {} ); // $ExpectError - reduceRightAsync.factory( true ); // $ExpectError - reduceRightAsync.factory( false ); // $ExpectError - reduceRightAsync.factory( {}, 123 ); // $ExpectError - reduceRightAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1( 12, acc, done ); // $ExpectError - fcn1( true, acc, done ); // $ExpectError - fcn1( false, acc, done ); // $ExpectError - fcn1( {}, acc, done ); // $ExpectError - - fcn1( [ 3000, 2500, 1000 ], acc, 12 ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, true ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, false ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, '5' ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, {} ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, [] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1(); // $ExpectError - fcn1( [ 3000, 2500, 1000 ] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - reduceRightAsync.factory( { 'limit': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': true }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': false }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - reduceRightAsync.factory( { 'series': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': 12 }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - reduceRightAsync.factory(); // $ExpectError - reduceRightAsync.factory( {}, reducer, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index dd64345..0000000 --- a/examples/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var resolve = require( 'path' ).resolve; -var readFile = require( '@stdlib/fs-read-file' ); -var reduceRightAsync = require( './../lib' ); - -var files = [ - resolve( __dirname, '..', 'package.json' ), - resolve( __dirname, '..', 'README.md' ) -]; - -function done( error, acc ) { - if ( error ) { - throw error; - } - console.log( acc.count ); -} - -function read( acc, file, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( file, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( null, acc ); - } - acc.count += 1; - next( null, acc ); - } -} - -var acc = { - 'count': 0 -}; -reduceRightAsync( files, acc, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index b19e443..9dc0658 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { Collection } from '@stdlib/types/object'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..2270aa3 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.8-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";function m(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("0id30","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!d(e.limit))?new TypeError(r("0id3b","limit",e.limit)):null):new TypeError(r("0id2h",t))}function c(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){if(this instanceof e){var i=[null];i.push.apply(i,arguments);var r=Function.bind.apply(t,i);return new r}return t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var f=c(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function p(e,t,i,r,s){var n,o,l,d,m,c;if(d=e.length,f("Collection length: %d",d),0===d)return f("Finished processing a collection."),s(null,t);for(l=d0&&p();function p(){function s(e,i){if(!o){if(e)return o=!0,u(e);f("Accumulator: %s",JSON.stringify(i)),t=i,u()}}f("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function u(e){return e?(f("Encountered an error: %s",e.message),s(e)):(f("Processed %d of %d collection elements.",n+=1,d),m>0?p():n===d?(f("Finished processing a collection."),s(null,t)):void 0)}}function u(e,n){var o,l,d;if(o={},arguments.length>1){if(l=m(o,e))throw l;d=n}else d=e;if(!t(d))throw new TypeError(r("0id43",d));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=s),c;function c(e,s,n){if(!i(e))throw new TypeError(r("0idBO",e));if(!t(n))throw new TypeError(r("0id43",n));return p(e,s,o,d,(function(e,t){if(e)return n(e);n(null,t)}))}}function a(e,t,i,r,s){if(arguments.length<5)return u(i)(e,t,r);u(i,r)(e,t,s)}e(a,"factory",u);export{a as default,u as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..078f301 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '0id2h', 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( '0id30', '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( '0id3b', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0id43', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '0idBO', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0id43', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","logger","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly","main"],"mappings":";;u2BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUR,EAAKK,SAGnDF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASR,EAAKS,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASP,GAkBzC,8eC/CIU,uDAAQC,CAAQ,4BAkBpB,SAASH,EAAOI,EAAYC,EAAKd,EAAMe,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMP,EAAWU,OACjBZ,EAAO,wBAAyBS,GAEnB,IAARA,EAEJ,OADAT,EAAO,qCACAK,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAEZE,EAAO,wBAAyBQ,GAChCR,EAAO,0BAA2BI,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdf,EAAO,kBAAmBkB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,GAPC,CAQD,CA5BDjB,EAAO,6BADPU,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJf,EAAO,2BAA4Be,EAAMM,SAClChB,EAAMU,KAGdf,EAAO,0CADPM,GAAS,EACgDG,GACpDC,EAAM,EACHG,IAEHP,IAAUG,GACdT,EAAO,qCACAK,EAAM,KAAMF,SAFpB,EAIA,CACF,CCzCA,SAASmB,EAAShC,EAASc,GAC1B,IAAIf,EACAkC,EACAC,EAGJ,GADAnC,EAAO,CAAA,EACFoC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMnC,EAAUC,EAAMC,GAErB,MAAMiC,EAEPC,EAAIpB,CACN,MACEoB,EAAIlC,EAEL,IAAMoC,EAAYF,GACjB,MAAM,IAAI5B,UAAWC,EAAQ,QAAS2B,IAUvC,YARqB,IAAhBnC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ6B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIN,UAAWC,EAAQ,QAASK,IAEvC,IAAMwB,EAAYrB,GACjB,MAAM,IAAIT,UAAWC,EAAQ,QAASQ,IAEvC,OAAOP,EAAOI,EAAY2B,EAASxC,EAAMmC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,EACZ,GACD,CACF,CC1EA,SAASyB,EAAkB1B,EAAY2B,EAASvC,EAASc,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAShC,EAATgC,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAShC,EAASc,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,EAC/C,CClBA0B,EAAAC,EAAA,UAAAV"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index f9448f7..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,164 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var validate = require( './validate.js' ); -var limit = require( './limit.js' ); - - -// MAIN // - -/** -* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} last argument must be a function -* @returns {Function} function which invokes the provided function once for each element in a collection -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error, data ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var opts = { -* 'series': false -* }; -* -* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: -* var reduceRightAsync = factory( opts, read ); -* -* // Create a collection over which to iterate: -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* // Define a callback which handles errors: -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* // Run `read` for each element in `files`: -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, done ); -*/ -function factory( options, fcn ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = fcn; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '0id43', f ) ); - } - if ( opts.series === void 0 && opts.limit === void 0 ) { - opts.series = true; - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return reduceRightAsync; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * @private - * @param {Collection} collection - input collection - * @param {*} initial - initial value - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be a collection - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function reduceRightAsync( collection, initial, done ) { - if ( !isCollection( collection ) ) { - throw new TypeError( format( '0idBO', collection ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '0id43', done ) ); - } - return limit( collection, initial, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {*} [acc] - accumulated value - * @returns {void} - */ - function clbk( error, acc ) { - if ( error ) { - return done( error ); - } - done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ae657ff..0000000 --- a/lib/index.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* @module @stdlib/utils-async-reduce-right -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' ); -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/limit.js b/lib/limit.js deleted file mode 100644 index cdb60af..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); - - -// VARIABLES // - -var debug = logger( 'reduce-right-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each element in a collection, limiting the number of concurrently pending functions and iterating from right to left. -* -* @private -* @param {Collection} collection - input collection -* @param {*} acc - initial value -* @param {Options} opts - function options -* @param {*} [opts.thisArg] - execution context -* @param {PositiveInteger} [opts.limit] - maximum number of pending function invocations -* @param {Function} fcn - function to invoke -* @param {Callback} done - function to invoke upon completion or upon encountering an error -* @returns {void} -*/ -function limit( collection, acc, opts, fcn, done ) { - var count; - var flg; - var lim; - var len; - var idx; - var i; - - len = collection.length; - debug( 'Collection length: %d', len ); - - if ( len === 0 ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - count = 0; - idx = len; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all collection elements... - if ( idx > 0 ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next element in a collection. - * - * @private - */ - function next() { - idx -= 1; - debug( 'Collection element %d: %s.', idx, JSON.stringify( collection[ idx ] ) ); - if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], cb ); - } else if ( fcn.length === 4 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, cb ); - } else { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len - } - /** - * Callback invoked once a provided function finishes processing a collection element. - * - * @private - * @param {*} [error] - error - * @param {*} [result] - accumulation result - * @returns {void} - */ - function cb( error, result ) { - if ( flg ) { - // Prevent further processing of collection elements: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Accumulator: %s', JSON.stringify( result ) ); - acc = result; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next collection element. - * - * @private - * @param {*} [error] - error - * @returns {void} - */ - function clbk( error ) { - if ( error ) { - debug( 'Encountered an error: %s', error.message ); - return done( error ); - } - count += 1; - debug( 'Processed %d of %d collection elements.', count, len ); - if ( idx > 0 ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index c8b0d0f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param {Collection} collection - input collection -* @param {*} initial - initial value -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} second-to-last argument must be a function -* @throws {TypeError} last argument must be a function -* @returns {void} -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -function reduceRightAsync( collection, initial, options, fcn, done ) { - if ( arguments.length < 5 ) { - return factory( options )( collection, initial, fcn ); - } - factory( options, fcn )( collection, initial, done ); -} - - -// EXPORTS // - -module.exports = reduceRightAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 6292663..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @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 -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'thisArg': {}, -* 'series': false, -* 'limit': 10 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '0id2h', options ) ); - } - if ( hasOwnProp( options, 'thisArg' ) ) { - opts.thisArg = options.thisArg; - } - if ( hasOwnProp( options, 'series' ) ) { - opts.series = options.series; - if ( !isBoolean( opts.series ) ) { - return new TypeError( format( '0id30', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '0id3b', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 8660367..cfe057f 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.8", "description": "Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,43 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.0.7", - "@stdlib/assert-is-boolean": "^0.0.8", - "@stdlib/assert-is-collection": "^0.0.8", - "@stdlib/assert-is-function": "^0.0.8", - "@stdlib/assert-is-plain-object": "^0.0.7", - "@stdlib/assert-is-positive-integer": "^0.0.7", - "@stdlib/constants-float64-pinf": "^0.0.8", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/types": "^0.0.14", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.12", - "@stdlib/constants-float64-eps": "^0.0.8", - "@stdlib/fs-read-file": "^0.0.8", - "@stdlib/utils-noop": "^0.0.14", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..47c2b4c --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 8244931..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1095 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( {}, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, next ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - factory( opts, next ); - }; - } -}); - -tape( 'the function returns a function (no options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided a collection (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a collection (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (1 argument)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (2 arguments)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with five arguments', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn() { - var value; - var next; - var acc; - var k; - - acc = arguments[ 0 ]; - value = arguments[ 1 ]; - k = arguments[ 2 ]; - next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( k, i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the returned function supports processing collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements concurrently', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 100, 250, 300 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements sequentially (limit = 1)', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of collection elements which are processed at any one time', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 250, 300, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 250, 100, 300 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var reduceRightAsync; - var arr; - - reduceRightAsync = factory( fcn ); - arr = []; - - reduceRightAsync( arr, 0, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var reduceRightAsync; - var obj; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = []; - obj = {}; - reduceRightAsync( arr, obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - i = 0; - - reduceRightAsync( arr, {}, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, acc ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the returned function does not skip empty elements', function test( t ) { - var reduceRightAsync; - var expected; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index f273a40..0000000 --- a/test/test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof reduceRightAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 1893240..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1035 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a collection', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (no options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, next, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, 0 ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - reduceRightAsync( [ 1, 2, 3 ], 0, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (1 argument)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (2 arguments)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with five arguments', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn() { - var next; - var acc; - var v; - - next = arguments[ 4 ]; - acc = arguments[ 0 ]; - v = arguments[ 1 ]; - - i -= 1; - j += 1; - - t.strictEqual( v, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, v ); - - function onTimeout() { - acc.sum += v; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'by default, the function processes collection elements sequentially', function test( t ) { - var values; - var count; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements concurrently', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 100, 250, 300 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': true - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially (limit = 1)', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var arr; - var ctx; - - arr = [ 3, 2, 1 ]; - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 3, 2, 1 ]; - opts = { - 'series': true - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 250, 100, 300 ]; - opts = { - 'limit': 2 - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var arr = []; - reduceRightAsync( arr, 0, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var arr = []; - var obj = {}; - - reduceRightAsync( arr, obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - arr = [ 3, 2, 1 ]; - i = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, value ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the function does not skip empty elements', function test( t ) { - var expected; - var arr; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, fcn, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 7660838..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,181 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `limit` option which is not a positive integer', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - -5, - 0, - 3.14, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'limit': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `series` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'series': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function accepts any value for the `thisArg` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'thisArg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err, null, 'returns null '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'thisArg': {}, - 'series': false, - 'limit': 10 - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From 958205640ba279b2d625895c20295a376915ff45 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 20 Sep 2023 23:09:46 +0000 Subject: [PATCH 062/147] Transform error messages --- lib/factory.js | 8 ++++---- lib/validate.js | 8 ++++---- package.json | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 1125052..1cd0d47 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -22,7 +22,7 @@ var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var PINF = require( '@stdlib/constants-float64-pinf' ); var validate = require( './validate.js' ); var limit = require( './limit.js' ); @@ -109,7 +109,7 @@ function factory( options, fcn ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '1RZ3q,JV', f ) ); } if ( opts.series === void 0 && opts.limit === void 0 ) { opts.series = true; @@ -134,10 +134,10 @@ function factory( options, fcn ) { */ function reduceRightAsync( collection, initial, done ) { if ( !isCollection( collection ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a collection. Value: `%s`.', collection ) ); + throw new TypeError( format( '1RZAh,O3', collection ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '1RZ3q,JV', done ) ); } return limit( collection, initial, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index 9ba927e..c90c17f 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,7 +54,7 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '1RZ2V,FD', options ) ); } if ( hasOwnProp( options, 'thisArg' ) ) { opts.thisArg = options.thisArg; @@ -62,13 +62,13 @@ function validate( opts, options ) { if ( hasOwnProp( options, 'series' ) ) { opts.series = options.series; if ( !isBoolean( opts.series ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'series', opts.series ) ); + return new TypeError( format( '1RZ2o,GE', 'series', opts.series ) ); } } if ( hasOwnProp( options, 'limit' ) ) { opts.limit = options.limit; if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'limit', opts.limit ) ); + return new TypeError( format( '1RZ3P,Fv', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index e0057f8..8660367 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-plain-object": "^0.0.7", "@stdlib/assert-is-positive-integer": "^0.0.7", "@stdlib/constants-float64-pinf": "^0.0.8", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/types": "^0.0.14", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7", "debug": "^2.6.9" From 381324b3529e141e9881869ba77163fff61152c7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 20 Sep 2023 23:18:56 +0000 Subject: [PATCH 063/147] Remove files --- index.d.ts | 415 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6597 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 9dc0658..0000000 --- a/index.d.ts +++ /dev/null @@ -1,415 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Collection } from '@stdlib/types/object'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * The maximum number of pending invocations at any one time. - */ - limit?: number; - - /** - * Boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection (default: true). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback function. -*/ -type Nullary = () => void; - -/** -* Callback function. -* -* @param error - encountered error or null -*/ -type Unary = ( error: Error | null ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Binary = ( error: Error | null, accumulator: any ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param next - a callback to be invoked after processing a collection `value` -*/ -type TernaryReducer = ( accumulator: any, value: any, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuaternaryReducer = ( accumulator: any, value: any, index: number, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuinaryReducer = ( accumulator: any, value: any, index: number, collection: Collection, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type Reducer = TernaryReducer | QuaternaryReducer | QuinaryReducer; - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result. -* -* @param collection - input collection -* @param initial - initial value -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( collection: Collection, initial: any, done: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Interface for `reduceRightAsync`. -*/ -interface ReduceRightAsync { - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, {}, read, done ); - */ - ( collection: Collection, initial: any, options: Options, reducer: Reducer, done: Callback ): void; // tslint-disable-line max-line-length - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, read, done ); - */ - ( collection: Collection, initial: any, reducer: Reducer, done: Callback ): void; // tslint-disable-line max-line-length - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @throws must provide valid options - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var opts = { - * 'series': false - * }; - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( opts, read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( options: Options, reducer: Reducer ): FactoryFunction; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * - * @param reducer - function to invoke for each element in a collection - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( reducer: Reducer ): FactoryFunction; -} - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* -* @param collection - input collection -* @param initial - initial value -* @param options - function options -* @param options.thisArg - execution context -* @param options.limit - maximum number of pending invocations at any one time -* @param 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 (default: true) -* @param reducer - function to invoke for each element in a collection -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( `@stdlib/fs/read-file` ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -declare var reduceRightAsync: ReduceRightAsync; - - -// EXPORTS // - -export = reduceRightAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 2270aa3..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.8-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";function m(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("0id30","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!d(e.limit))?new TypeError(r("0id3b","limit",e.limit)):null):new TypeError(r("0id2h",t))}function c(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){if(this instanceof e){var i=[null];i.push.apply(i,arguments);var r=Function.bind.apply(t,i);return new r}return t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var f=c(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function p(e,t,i,r,s){var n,o,l,d,m,c;if(d=e.length,f("Collection length: %d",d),0===d)return f("Finished processing a collection."),s(null,t);for(l=d0&&p();function p(){function s(e,i){if(!o){if(e)return o=!0,u(e);f("Accumulator: %s",JSON.stringify(i)),t=i,u()}}f("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function u(e){return e?(f("Encountered an error: %s",e.message),s(e)):(f("Processed %d of %d collection elements.",n+=1,d),m>0?p():n===d?(f("Finished processing a collection."),s(null,t)):void 0)}}function u(e,n){var o,l,d;if(o={},arguments.length>1){if(l=m(o,e))throw l;d=n}else d=e;if(!t(d))throw new TypeError(r("0id43",d));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=s),c;function c(e,s,n){if(!i(e))throw new TypeError(r("0idBO",e));if(!t(n))throw new TypeError(r("0id43",n));return p(e,s,o,d,(function(e,t){if(e)return n(e);n(null,t)}))}}function a(e,t,i,r,s){if(arguments.length<5)return u(i)(e,t,r);u(i,r)(e,t,s)}e(a,"factory",u);export{a as default,u as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 078f301..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '0id2h', 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( '0id30', '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( '0id3b', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0id43', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '0idBO', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0id43', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","logger","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly","main"],"mappings":";;u2BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUR,EAAKK,SAGnDF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASR,EAAKS,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASP,GAkBzC,8eC/CIU,uDAAQC,CAAQ,4BAkBpB,SAASH,EAAOI,EAAYC,EAAKd,EAAMe,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMP,EAAWU,OACjBZ,EAAO,wBAAyBS,GAEnB,IAARA,EAEJ,OADAT,EAAO,qCACAK,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAEZE,EAAO,wBAAyBQ,GAChCR,EAAO,0BAA2BI,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdf,EAAO,kBAAmBkB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,GAPC,CAQD,CA5BDjB,EAAO,6BADPU,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJf,EAAO,2BAA4Be,EAAMM,SAClChB,EAAMU,KAGdf,EAAO,0CADPM,GAAS,EACgDG,GACpDC,EAAM,EACHG,IAEHP,IAAUG,GACdT,EAAO,qCACAK,EAAM,KAAMF,SAFpB,EAIA,CACF,CCzCA,SAASmB,EAAShC,EAASc,GAC1B,IAAIf,EACAkC,EACAC,EAGJ,GADAnC,EAAO,CAAA,EACFoC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMnC,EAAUC,EAAMC,GAErB,MAAMiC,EAEPC,EAAIpB,CACN,MACEoB,EAAIlC,EAEL,IAAMoC,EAAYF,GACjB,MAAM,IAAI5B,UAAWC,EAAQ,QAAS2B,IAUvC,YARqB,IAAhBnC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ6B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIN,UAAWC,EAAQ,QAASK,IAEvC,IAAMwB,EAAYrB,GACjB,MAAM,IAAIT,UAAWC,EAAQ,QAASQ,IAEvC,OAAOP,EAAOI,EAAY2B,EAASxC,EAAMmC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,EACZ,GACD,CACF,CC1EA,SAASyB,EAAkB1B,EAAY2B,EAASvC,EAASc,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAShC,EAATgC,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAShC,EAASc,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,EAC/C,CClBA0B,EAAAC,EAAA,UAAAV"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 47c2b4c..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From f26b9971b8ef037eefe26dc76bebd5e351312848 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 20 Sep 2023 23:19:34 +0000 Subject: [PATCH 064/147] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 783 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 47 +- benchmark/benchmark.factory.js | 73 - benchmark/benchmark.js | 160 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 224 - docs/types/test.ts | 166 - examples/index.js | 55 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 164 - lib/index.js | 77 - lib/limit.js | 142 - lib/main.js | 95 - lib/validate.js | 80 - package.json | 64 +- stats.html | 6177 +++++++++++++++++++++ test/test.factory.js | 1095 ---- test/test.js | 38 - test/test.main.js | 1035 ---- test/test.validate.js | 181 - 47 files changed, 6208 insertions(+), 6847 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/limit.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1e08946..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 663f5df..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 45a5053..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '37 1 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 91f2b93..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,783 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -458,7 +457,7 @@ reduceRightAsync( files, acc, read, done ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -526,11 +525,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right +[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right/tree/esm -[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce +[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/tree/esm diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 46d8b83..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var reduceRightAsync; - var arr; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - reduceRightAsync = factory( onItem ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - var acc; - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 6ad0714..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var reduceRightAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=false', function benchmark( b ) { - var opts; - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'series': false - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var arr; - var len; - var acc; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'limit': 3 - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index acfc6d6..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right" -%% click B href "https://github.com/stdlib-js/utils-async-reduce-right/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-reduce-right/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-reduce-right/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-reduce-right/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right -[production-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 47a072e..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import reduceRightAsync from '../docs/types/index'; -export = reduceRightAsync; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 530ca4d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var c=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var x=c(function(U,O){ -var R=require('@stdlib/assert-is-plain-object/dist'),h=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,k=require('@stdlib/assert-is-positive-integer/dist').isPrimitive,d=require('@stdlib/error-tools-fmtprodmsg/dist');function I(e,r){return R(r)?(h(r,"thisArg")&&(e.thisArg=r.thisArg),h(r,"series")&&(e.series=r.series,!j(e.series))?new TypeError(d('1RZ2o',"series",e.series)):h(r,"limit")&&(e.limit=r.limit,!k(e.limit))?new TypeError(d('1RZ3P',"limit",e.limit)):null):new TypeError(d('1RZ2V',r));}O.exports=I -});var P=c(function(W,E){ -var J=require("debug"),a=J("reduce-right-async:limit");function L(e,r,i,t,s){var f,m,v,n,u,g;if(n=e.length,a("Collection length: %d",n),n===0)return a("Finished processing a collection."),s(null,r);for(n0&&o();function o(){u-=1,a("Collection element %d: %s.",u,JSON.stringify(e[u])),t.length===3?t.call(i.thisArg,r,e[u],l):t.length===4?t.call(i.thisArg,r,e[u],u,l):t.call(i.thisArg,r,e[u],u,e,l);function l(w,A){if(!m){if(w)return m=!0,b(w);a("Accumulator: %s",JSON.stringify(A)),r=A,b()}}}function b(l){if(l)return a("Encountered an error: %s",l.message),s(l);if(f+=1,a("Processed %d of %d collection elements.",f,n),u>0)return o();if(f===n)return a("Finished processing a collection."),s(null,r)}}E.exports=L -});var q=c(function(X,F){ -var T=require('@stdlib/assert-is-function/dist'),S=require('@stdlib/assert-is-collection/dist'),y=require('@stdlib/error-tools-fmtprodmsg/dist'),B=require('@stdlib/constants-float64-pinf/dist'),z=x(),D=P();function G(e,r){var i,t,s;if(i={},arguments.length>1){if(t=z(i,e),t)throw t;s=r}else s=e;if(!T(s))throw new TypeError(y('1RZ3q',s));return i.series===void 0&&i.limit===void 0&&(i.series=!0),i.series?i.limit=1:i.limit||(i.limit=B),f;function f(m,v,n){if(!S(m))throw new TypeError(y('1RZAh',m));if(!T(n))throw new TypeError(y('1RZ3q',n));return D(m,v,i,s,u);function u(g,o){if(g)return n(g);n(null,o)}}}F.exports=G -});var N=c(function(Y,C){ -var p=q();function H(e,r,i,t,s){if(arguments.length<5)return p(i)(e,r,t);p(i,t)(e,r,s)}C.exports=H -});var K=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),V=N(),M=q();K(V,"factory",M);module.exports=V; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index acb9d67..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/limit.js", "../lib/factory.js", "../lib/main.js", "../lib/index.js"], - "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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\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 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 to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\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 === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, 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 ( !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, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\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* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nmodule.exports = reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' );\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, 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"], - "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,0BAA2B,EAkB/C,SAASE,EAAOC,EAAYC,EAAKC,EAAMC,EAAKC,EAAO,CAClD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMR,EAAW,OACjBF,EAAO,wBAAyBU,CAAI,EAE/BA,IAAQ,EACZ,OAAAV,EAAO,mCAAoC,EACpCM,EAAM,KAAMH,CAAI,EAYxB,IAVKO,EAAMN,EAAK,MACfK,EAAMC,EAEND,EAAML,EAAK,MAEZJ,EAAO,wBAAyBS,CAAI,EACpCT,EAAO,0BAA2BK,EAAI,MAAO,EAE7CE,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVE,EAAK,EAQP,SAASA,GAAO,CACfF,GAAO,EACPX,EAAO,6BAA8BW,EAAK,KAAK,UAAWT,EAAYS,CAAI,CAAE,CAAE,EACzEN,EAAI,SAAW,EACnBA,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGG,CAAG,EACxCT,EAAI,SAAW,EAC1BA,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGA,EAAKG,CAAG,EAExDT,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGA,EAAKT,EAAYY,CAAG,EAUrE,SAASA,EAAIC,EAAOC,EAAS,CAC5B,GAAK,CAAAR,EAIL,IAAKO,EACJ,OAAAP,EAAM,GACCS,EAAMF,CAAM,EAEpBf,EAAO,kBAAmB,KAAK,UAAWgB,CAAO,CAAE,EACnDb,EAAMa,EACNC,EAAK,EACN,CACD,CASA,SAASA,EAAMF,EAAQ,CACtB,GAAKA,EACJ,OAAAf,EAAO,2BAA4Be,EAAM,OAAQ,EAC1CT,EAAMS,CAAM,EAIpB,GAFAR,GAAS,EACTP,EAAO,0CAA2CO,EAAOG,CAAI,EACxDC,EAAM,EACV,OAAOE,EAAK,EAEb,GAAKN,IAAUG,EACd,OAAAV,EAAO,mCAAoC,EACpCM,EAAM,KAAMH,CAAI,CAEzB,CACD,CAKAL,EAAO,QAAUG,IC7IjB,IAAAiB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,gCAAiC,EACjDC,EAAW,IACXC,EAAQ,IAoEZ,SAASC,EAASC,EAASC,EAAM,CAChC,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,CAACP,EAAYW,CAAE,EACnB,MAAM,IAAI,UAAWT,EAAQ,mEAAoES,CAAE,CAAE,EAEtG,OAAKF,EAAK,SAAW,QAAUA,EAAK,QAAU,SAC7CA,EAAK,OAAS,IAEVA,EAAK,OACTA,EAAK,MAAQ,EACDA,EAAK,QACjBA,EAAK,MAAQN,GAEPS,EAaP,SAASA,EAAkBC,EAAYC,EAASC,EAAO,CACtD,GAAK,CAACd,EAAcY,CAAW,EAC9B,MAAM,IAAI,UAAWX,EAAQ,sEAAuEW,CAAW,CAAE,EAElH,GAAK,CAACb,EAAYe,CAAK,EACtB,MAAM,IAAI,UAAWb,EAAQ,mEAAoEa,CAAK,CAAE,EAEzG,OAAOV,EAAOQ,EAAYC,EAASL,EAAME,EAAGK,CAAK,EAUjD,SAASA,EAAMC,EAAOC,EAAM,CAC3B,GAAKD,EACJ,OAAOF,EAAME,CAAM,EAEpBF,EAAM,KAAMG,CAAI,CACjB,CACD,CACD,CAKAnB,EAAO,QAAUO,ICnKjB,IAAAa,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,IA8Dd,SAASC,EAAkBC,EAAYC,EAASC,EAASC,EAAKC,EAAO,CACpE,GAAK,UAAU,OAAS,EACvB,OAAON,EAASI,CAAQ,EAAGF,EAAYC,EAASE,CAAI,EAErDL,EAASI,EAASC,CAAI,EAAGH,EAAYC,EAASG,CAAK,CACpD,CAKAP,EAAO,QAAUE,IC9BjB,IAAIM,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "isPositiveInteger", "format", "validate", "opts", "options", "require_limit", "__commonJSMin", "exports", "module", "logger", "debug", "limit", "collection", "acc", "opts", "fcn", "done", "count", "flg", "lim", "len", "idx", "i", "next", "cb", "error", "result", "clbk", "require_factory", "__commonJSMin", "exports", "module", "isFunction", "isCollection", "format", "PINF", "validate", "limit", "factory", "options", "fcn", "opts", "err", "f", "reduceRightAsync", "collection", "initial", "done", "clbk", "error", "acc", "require_main", "__commonJSMin", "exports", "module", "factory", "reduceRightAsync", "collection", "initial", "options", "fcn", "done", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3f22669..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,224 +0,0 @@ - -{{alias}}( collection, initial, [options,] reducer, done ) - Applies a function against an accumulator and each element in a collection - and returns the accumulated result, iterating from right to left. - - When invoked, `reducer` is provided a maximum of five arguments: - - - `accumulator`: accumulated value - - `value`: collection value - - `index`: collection index - - `collection`: the input collection - - `next`: a callback to be invoked after processing a collection `value` - - The actual number of provided arguments depends on function length. If - `reducer` accepts three arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `next` - - If `reducer` accepts four arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `index` - - `next` - - For every other `reducer` signature, `reducer` is provided all five - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `accumulator`: accumulated value - - If a provided function calls the `next` callback with a truthy `error` - argument, the function suspends execution and immediately calls the `done` - callback for subsequent `error` handling. - - Execution is *not* guaranteed to be asynchronous. To guarantee asynchrony, - 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`). - - The function does not support dynamic collection resizing. - - If provided an empty collection, the function invokes the `done` callback - with the `initial` value as the second argument. - - The function does not skip `undefined` elements. - - When processing collection elements concurrently, *beware* of race - conditions when updating an accumulator. This is especially true when an - accumulator is a primitive (e.g., a number). In general, prefer object - accumulators. - - Parameters - ---------- - collection: Array|TypedArray|Object - Input collection over which to iterate. If provided an object, the - object must be array-like (excluding strings and functions). - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - reducer: Function - The function to invoke for each element in a collection. - - done: Function - A callback invoked either upon processing all collection elements or - upon encountering an error. - - Examples - -------- - // Basic usage: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, fcn, done ) - 3000 - 2500 - 1000 - 6500 - - // Limit number of concurrent invocations: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'limit': 2 }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 2500 - 3000 - 1000 - 6500 - - // Process concurrently: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'series': false }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 1000 - 2500 - 3000 - 6500 - - -{{alias}}.factory( [options,] fcn ) - Returns a function which applies a function against an accumulator and each - element in a collection and returns the accumulated result, iterating from - right to left. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - fcn: Function - The function to invoke for each element in a collection. - - Returns - ------- - out: Function - A function which invokes a function for each element in a collection. - - Examples - -------- - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > var opts = { 'series': false }; - > var f = {{alias}}.factory( opts, fcn ); - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > f( arr, acc, done ) - 1000 - 2500 - 3000 - 6500 - > acc = { 'sum': 0 }; - > arr = [ 1000, 1500, 2000 ]; - > f( arr, acc, done ) - 1000 - 1500 - 2000 - 4500 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index f0001b3..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,166 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unsafe-any */ - -import reduceRightAsync = require( './index' ); - -const reducer = ( acc: any, value: number, index: number, next: Function ) => { - acc.sum += value; - if ( index === void 0 ) { - throw new Error( '`index` is missing.' ); - } - next( null, acc ); -}; - -const done = ( error: Error | null, acc: any ) => { - if ( error ) { - throw error; - } - if ( acc === void 0 ) { - throw new Error( '`acc` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( 2, acc, reducer, done ); // $ExpectError - reduceRightAsync( false, acc, reducer, done ); // $ExpectError - reduceRightAsync( true, acc, reducer, done ); // $ExpectError - reduceRightAsync( {}, acc, reducer, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a predicate argument which is not a predicate function... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 2, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, false, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, true, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 'abc', done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, [], done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a done callback argument which is not a function having a supported signature... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 2 ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, false ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, true ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 'abc' ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, {} ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, [] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const acc = { 'sum': 0 }; - reduceRightAsync(); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, reducer, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - reduceRightAsync.factory( reducer ); // $ExpectType FactoryFunction - reduceRightAsync.factory( { 'series': true }, reducer ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - reduceRightAsync.factory( [], reducer ); // $ExpectError - reduceRightAsync.factory( 123, reducer ); // $ExpectError - reduceRightAsync.factory( 'abc', reducer ); // $ExpectError - reduceRightAsync.factory( false, reducer ); // $ExpectError - reduceRightAsync.factory( true, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not a predicate function... -{ - reduceRightAsync.factory( {} ); // $ExpectError - reduceRightAsync.factory( true ); // $ExpectError - reduceRightAsync.factory( false ); // $ExpectError - reduceRightAsync.factory( {}, 123 ); // $ExpectError - reduceRightAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1( 12, acc, done ); // $ExpectError - fcn1( true, acc, done ); // $ExpectError - fcn1( false, acc, done ); // $ExpectError - fcn1( {}, acc, done ); // $ExpectError - - fcn1( [ 3000, 2500, 1000 ], acc, 12 ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, true ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, false ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, '5' ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, {} ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, [] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1(); // $ExpectError - fcn1( [ 3000, 2500, 1000 ] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - reduceRightAsync.factory( { 'limit': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': true }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': false }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - reduceRightAsync.factory( { 'series': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': 12 }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - reduceRightAsync.factory(); // $ExpectError - reduceRightAsync.factory( {}, reducer, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index dd64345..0000000 --- a/examples/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var resolve = require( 'path' ).resolve; -var readFile = require( '@stdlib/fs-read-file' ); -var reduceRightAsync = require( './../lib' ); - -var files = [ - resolve( __dirname, '..', 'package.json' ), - resolve( __dirname, '..', 'README.md' ) -]; - -function done( error, acc ) { - if ( error ) { - throw error; - } - console.log( acc.count ); -} - -function read( acc, file, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( file, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( null, acc ); - } - acc.count += 1; - next( null, acc ); - } -} - -var acc = { - 'count': 0 -}; -reduceRightAsync( files, acc, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 80786cf..2657f80 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..60b8c78 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.8-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";function m(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("1RZ2o,GE","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!d(e.limit))?new TypeError(r("1RZ3P,Fv","limit",e.limit)):null):new TypeError(r("1RZ2V,FD",t))}function c(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){if(this instanceof e){var i=[null];i.push.apply(i,arguments);var r=Function.bind.apply(t,i);return new r}return t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var f=c(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function p(e,t,i,r,s){var n,o,l,d,m,c;if(d=e.length,f("Collection length: %d",d),0===d)return f("Finished processing a collection."),s(null,t);for(l=d0&&p();function p(){function s(e,i){if(!o){if(e)return o=!0,u(e);f("Accumulator: %s",JSON.stringify(i)),t=i,u()}}f("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function u(e){return e?(f("Encountered an error: %s",e.message),s(e)):(f("Processed %d of %d collection elements.",n+=1,d),m>0?p():n===d?(f("Finished processing a collection."),s(null,t)):void 0)}}function u(e,n){var o,l,d;if(o={},arguments.length>1){if(l=m(o,e))throw l;d=n}else d=e;if(!t(d))throw new TypeError(r("1RZ3q,JV",d));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=s),c;function c(e,s,n){if(!i(e))throw new TypeError(r("1RZAh,O3",e));if(!t(n))throw new TypeError(r("1RZ3q,JV",n));return p(e,s,o,d,(function(e,t){if(e)return n(e);n(null,t)}))}}function a(e,t,i,r,s){if(arguments.length<5)return u(i)(e,t,r);u(i,r)(e,t,s)}e(a,"factory",u);export{a as default,u as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..7337f60 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '1RZ2V,FD', 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( '1RZ2o,GE', '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( '1RZ3P,Fv', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RZ3q,JV', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '1RZAh,O3', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RZ3q,JV', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","logger","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly","main"],"mappings":";;u2BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,WAAY,SAAUR,EAAKK,SAGtDF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,WAAY,QAASR,EAAKS,QAGnD,MAjBC,IAAIF,UAAWC,EAAQ,WAAYP,GAkB5C,8eC/CIU,uDAAQC,CAAQ,4BAkBpB,SAASH,EAAOI,EAAYC,EAAKd,EAAMe,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMP,EAAWU,OACjBZ,EAAO,wBAAyBS,GAEnB,IAARA,EAEJ,OADAT,EAAO,qCACAK,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAEZE,EAAO,wBAAyBQ,GAChCR,EAAO,0BAA2BI,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdf,EAAO,kBAAmBkB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,GAPC,CAQD,CA5BDjB,EAAO,6BADPU,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJf,EAAO,2BAA4Be,EAAMM,SAClChB,EAAMU,KAGdf,EAAO,0CADPM,GAAS,EACgDG,GACpDC,EAAM,EACHG,IAEHP,IAAUG,GACdT,EAAO,qCACAK,EAAM,KAAMF,SAFpB,EAIA,CACF,CCzCA,SAASmB,EAAShC,EAASc,GAC1B,IAAIf,EACAkC,EACAC,EAGJ,GADAnC,EAAO,CAAA,EACFoC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMnC,EAAUC,EAAMC,GAErB,MAAMiC,EAEPC,EAAIpB,CACN,MACEoB,EAAIlC,EAEL,IAAMoC,EAAYF,GACjB,MAAM,IAAI5B,UAAWC,EAAQ,WAAY2B,IAU1C,YARqB,IAAhBnC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ6B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIN,UAAWC,EAAQ,WAAYK,IAE1C,IAAMwB,EAAYrB,GACjB,MAAM,IAAIT,UAAWC,EAAQ,WAAYQ,IAE1C,OAAOP,EAAOI,EAAY2B,EAASxC,EAAMmC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,EACZ,GACD,CACF,CC1EA,SAASyB,EAAkB1B,EAAY2B,EAASvC,EAASc,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAShC,EAATgC,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAShC,EAASc,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,EAC/C,CClBA0B,EAAAC,EAAA,UAAAV"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 1cd0d47..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,164 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var validate = require( './validate.js' ); -var limit = require( './limit.js' ); - - -// MAIN // - -/** -* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} last argument must be a function -* @returns {Function} function which invokes the provided function once for each element in a collection -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error, data ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var opts = { -* 'series': false -* }; -* -* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: -* var reduceRightAsync = factory( opts, read ); -* -* // Create a collection over which to iterate: -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* // Define a callback which handles errors: -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* // Run `read` for each element in `files`: -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, done ); -*/ -function factory( options, fcn ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = fcn; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '1RZ3q,JV', f ) ); - } - if ( opts.series === void 0 && opts.limit === void 0 ) { - opts.series = true; - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return reduceRightAsync; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * @private - * @param {Collection} collection - input collection - * @param {*} initial - initial value - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be a collection - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function reduceRightAsync( collection, initial, done ) { - if ( !isCollection( collection ) ) { - throw new TypeError( format( '1RZAh,O3', collection ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '1RZ3q,JV', done ) ); - } - return limit( collection, initial, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {*} [acc] - accumulated value - * @returns {void} - */ - function clbk( error, acc ) { - if ( error ) { - return done( error ); - } - done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ae657ff..0000000 --- a/lib/index.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* @module @stdlib/utils-async-reduce-right -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' ); -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/limit.js b/lib/limit.js deleted file mode 100644 index cdb60af..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); - - -// VARIABLES // - -var debug = logger( 'reduce-right-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each element in a collection, limiting the number of concurrently pending functions and iterating from right to left. -* -* @private -* @param {Collection} collection - input collection -* @param {*} acc - initial value -* @param {Options} opts - function options -* @param {*} [opts.thisArg] - execution context -* @param {PositiveInteger} [opts.limit] - maximum number of pending function invocations -* @param {Function} fcn - function to invoke -* @param {Callback} done - function to invoke upon completion or upon encountering an error -* @returns {void} -*/ -function limit( collection, acc, opts, fcn, done ) { - var count; - var flg; - var lim; - var len; - var idx; - var i; - - len = collection.length; - debug( 'Collection length: %d', len ); - - if ( len === 0 ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - count = 0; - idx = len; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all collection elements... - if ( idx > 0 ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next element in a collection. - * - * @private - */ - function next() { - idx -= 1; - debug( 'Collection element %d: %s.', idx, JSON.stringify( collection[ idx ] ) ); - if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], cb ); - } else if ( fcn.length === 4 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, cb ); - } else { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len - } - /** - * Callback invoked once a provided function finishes processing a collection element. - * - * @private - * @param {*} [error] - error - * @param {*} [result] - accumulation result - * @returns {void} - */ - function cb( error, result ) { - if ( flg ) { - // Prevent further processing of collection elements: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Accumulator: %s', JSON.stringify( result ) ); - acc = result; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next collection element. - * - * @private - * @param {*} [error] - error - * @returns {void} - */ - function clbk( error ) { - if ( error ) { - debug( 'Encountered an error: %s', error.message ); - return done( error ); - } - count += 1; - debug( 'Processed %d of %d collection elements.', count, len ); - if ( idx > 0 ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index c8b0d0f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param {Collection} collection - input collection -* @param {*} initial - initial value -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} second-to-last argument must be a function -* @throws {TypeError} last argument must be a function -* @returns {void} -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -function reduceRightAsync( collection, initial, options, fcn, done ) { - if ( arguments.length < 5 ) { - return factory( options )( collection, initial, fcn ); - } - factory( options, fcn )( collection, initial, done ); -} - - -// EXPORTS // - -module.exports = reduceRightAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index c90c17f..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @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 -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'thisArg': {}, -* 'series': false, -* 'limit': 10 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '1RZ2V,FD', options ) ); - } - if ( hasOwnProp( options, 'thisArg' ) ) { - opts.thisArg = options.thisArg; - } - if ( hasOwnProp( options, 'series' ) ) { - opts.series = options.series; - if ( !isBoolean( opts.series ) ) { - return new TypeError( format( '1RZ2o,GE', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '1RZ3P,Fv', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 8660367..cfe057f 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.8", "description": "Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,43 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.0.7", - "@stdlib/assert-is-boolean": "^0.0.8", - "@stdlib/assert-is-collection": "^0.0.8", - "@stdlib/assert-is-function": "^0.0.8", - "@stdlib/assert-is-plain-object": "^0.0.7", - "@stdlib/assert-is-positive-integer": "^0.0.7", - "@stdlib/constants-float64-pinf": "^0.0.8", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/types": "^0.0.14", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.12", - "@stdlib/constants-float64-eps": "^0.0.8", - "@stdlib/fs-read-file": "^0.0.8", - "@stdlib/utils-noop": "^0.0.14", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..60d2235 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 8244931..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1095 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( {}, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, next ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - factory( opts, next ); - }; - } -}); - -tape( 'the function returns a function (no options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided a collection (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a collection (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (1 argument)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (2 arguments)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with five arguments', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn() { - var value; - var next; - var acc; - var k; - - acc = arguments[ 0 ]; - value = arguments[ 1 ]; - k = arguments[ 2 ]; - next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( k, i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the returned function supports processing collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements concurrently', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 100, 250, 300 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements sequentially (limit = 1)', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of collection elements which are processed at any one time', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 250, 300, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 250, 100, 300 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var reduceRightAsync; - var arr; - - reduceRightAsync = factory( fcn ); - arr = []; - - reduceRightAsync( arr, 0, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var reduceRightAsync; - var obj; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = []; - obj = {}; - reduceRightAsync( arr, obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - i = 0; - - reduceRightAsync( arr, {}, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, acc ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the returned function does not skip empty elements', function test( t ) { - var reduceRightAsync; - var expected; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index f273a40..0000000 --- a/test/test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof reduceRightAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 1893240..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1035 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a collection', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (no options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, next, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, 0 ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - reduceRightAsync( [ 1, 2, 3 ], 0, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (1 argument)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (2 arguments)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with five arguments', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn() { - var next; - var acc; - var v; - - next = arguments[ 4 ]; - acc = arguments[ 0 ]; - v = arguments[ 1 ]; - - i -= 1; - j += 1; - - t.strictEqual( v, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, v ); - - function onTimeout() { - acc.sum += v; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'by default, the function processes collection elements sequentially', function test( t ) { - var values; - var count; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements concurrently', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 100, 250, 300 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': true - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially (limit = 1)', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var arr; - var ctx; - - arr = [ 3, 2, 1 ]; - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 3, 2, 1 ]; - opts = { - 'series': true - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 250, 100, 300 ]; - opts = { - 'limit': 2 - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var arr = []; - reduceRightAsync( arr, 0, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var arr = []; - var obj = {}; - - reduceRightAsync( arr, obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - arr = [ 3, 2, 1 ]; - i = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, value ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the function does not skip empty elements', function test( t ) { - var expected; - var arr; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, fcn, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 7660838..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,181 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `limit` option which is not a positive integer', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - -5, - 0, - 3.14, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'limit': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `series` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'series': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function accepts any value for the `thisArg` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'thisArg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err, null, 'returns null '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'thisArg': {}, - 'series': false, - 'limit': 10 - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From 6c41be78be3e0505507649350fc50aaedf6d763d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 23 Sep 2023 16:12:13 +0000 Subject: [PATCH 065/147] Transform error messages --- lib/factory.js | 8 ++++---- lib/validate.js | 8 ++++---- package.json | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 1125052..1cd0d47 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -22,7 +22,7 @@ var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var PINF = require( '@stdlib/constants-float64-pinf' ); var validate = require( './validate.js' ); var limit = require( './limit.js' ); @@ -109,7 +109,7 @@ function factory( options, fcn ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '1RZ3q,JV', f ) ); } if ( opts.series === void 0 && opts.limit === void 0 ) { opts.series = true; @@ -134,10 +134,10 @@ function factory( options, fcn ) { */ function reduceRightAsync( collection, initial, done ) { if ( !isCollection( collection ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a collection. Value: `%s`.', collection ) ); + throw new TypeError( format( '1RZAh,O3', collection ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '1RZ3q,JV', done ) ); } return limit( collection, initial, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index 9ba927e..c90c17f 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,7 +54,7 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '1RZ2V,FD', options ) ); } if ( hasOwnProp( options, 'thisArg' ) ) { opts.thisArg = options.thisArg; @@ -62,13 +62,13 @@ function validate( opts, options ) { if ( hasOwnProp( options, 'series' ) ) { opts.series = options.series; if ( !isBoolean( opts.series ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'series', opts.series ) ); + return new TypeError( format( '1RZ2o,GE', 'series', opts.series ) ); } } if ( hasOwnProp( options, 'limit' ) ) { opts.limit = options.limit; if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'limit', opts.limit ) ); + return new TypeError( format( '1RZ3P,Fv', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index 74b1a81..9d271e6 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-plain-object": "^0.1.0", "@stdlib/assert-is-positive-integer": "^0.1.0", "@stdlib/constants-float64-pinf": "^0.1.0", - "@stdlib/string-format": "^0.1.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.0", "@stdlib/types": "^0.1.0", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.0", "debug": "^2.6.9" From 21aa2afd59032d268994c051bda37dfe01eaf402 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 23 Sep 2023 17:43:08 +0000 Subject: [PATCH 066/147] Remove files --- index.d.ts | 410 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6592 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 2657f80..0000000 --- a/index.d.ts +++ /dev/null @@ -1,410 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Execution context. - */ - thisArg?: ThisParameterType>; - - /** - * The maximum number of pending invocations at any one time. - */ - limit?: number; - - /** - * Boolean indicating whether to sequentially invoke the reducer function for each `collection` element. If `true`, the function sets `options.limit=1`. Default: true. - */ - series?: boolean; -} - -/** -* Callback function. -*/ -type Nullary = () => void; - -/** -* Callback function. -* -* @param error - encountered error or null -*/ -type Unary = ( error: Error | null ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Binary = ( error: Error | null, accumulator: U ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param next - a callback to be invoked after processing a collection `value` -*/ -type TernaryReducer = ( this: V, accumulator: U, value: T, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuaternaryReducer = ( this: V, accumulator: U, value: T, index: number, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuinaryReducer = ( this: V, accumulator: U, value: T, index: number, collection: Collection, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type Reducer = TernaryReducer | QuaternaryReducer | QuinaryReducer; - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result. -* -* @param collection - input collection -* @param initial - initial value -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( collection: Collection, initial: U, done: Callback ) => void; - -/** -* Interface for `reduceRightAsync`. -*/ -interface ReduceRightAsync { - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, {}, read, done ); - */ - ( collection: Collection, initial: U, options: Options, reducer: Reducer, done: Callback ): void; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, read, done ); - */ - ( collection: Collection, initial: U, reducer: Reducer, done: Callback ): void; // tslint:disable-line:no-unnecessary-generics - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @throws must provide valid options - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var opts = { - * 'series': false - * }; - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( opts, read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( options: Options, reducer: Reducer ): FactoryFunction; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param reducer - function to invoke for each element in a collection - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( reducer: Reducer ): FactoryFunction; // tslint:disable-line:no-unnecessary-generics -} - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param collection - input collection -* @param initial - initial value -* @param options - function options -* @param options.thisArg - execution context -* @param options.limit - maximum number of pending invocations at any one time -* @param 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 (default: true) -* @param reducer - function to invoke for each element in a collection -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( `@stdlib/fs/read-file` ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -declare var reduceRightAsync: ReduceRightAsync; - - -// EXPORTS // - -export = reduceRightAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 60b8c78..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.8-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";function m(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("1RZ2o,GE","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!d(e.limit))?new TypeError(r("1RZ3P,Fv","limit",e.limit)):null):new TypeError(r("1RZ2V,FD",t))}function c(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){if(this instanceof e){var i=[null];i.push.apply(i,arguments);var r=Function.bind.apply(t,i);return new r}return t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var f=c(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function p(e,t,i,r,s){var n,o,l,d,m,c;if(d=e.length,f("Collection length: %d",d),0===d)return f("Finished processing a collection."),s(null,t);for(l=d0&&p();function p(){function s(e,i){if(!o){if(e)return o=!0,u(e);f("Accumulator: %s",JSON.stringify(i)),t=i,u()}}f("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function u(e){return e?(f("Encountered an error: %s",e.message),s(e)):(f("Processed %d of %d collection elements.",n+=1,d),m>0?p():n===d?(f("Finished processing a collection."),s(null,t)):void 0)}}function u(e,n){var o,l,d;if(o={},arguments.length>1){if(l=m(o,e))throw l;d=n}else d=e;if(!t(d))throw new TypeError(r("1RZ3q,JV",d));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=s),c;function c(e,s,n){if(!i(e))throw new TypeError(r("1RZAh,O3",e));if(!t(n))throw new TypeError(r("1RZ3q,JV",n));return p(e,s,o,d,(function(e,t){if(e)return n(e);n(null,t)}))}}function a(e,t,i,r,s){if(arguments.length<5)return u(i)(e,t,r);u(i,r)(e,t,s)}e(a,"factory",u);export{a as default,u as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 7337f60..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '1RZ2V,FD', 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( '1RZ2o,GE', '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( '1RZ3P,Fv', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RZ3q,JV', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '1RZAh,O3', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RZ3q,JV', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","logger","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly","main"],"mappings":";;u2BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,WAAY,SAAUR,EAAKK,SAGtDF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,WAAY,QAASR,EAAKS,QAGnD,MAjBC,IAAIF,UAAWC,EAAQ,WAAYP,GAkB5C,8eC/CIU,uDAAQC,CAAQ,4BAkBpB,SAASH,EAAOI,EAAYC,EAAKd,EAAMe,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMP,EAAWU,OACjBZ,EAAO,wBAAyBS,GAEnB,IAARA,EAEJ,OADAT,EAAO,qCACAK,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAEZE,EAAO,wBAAyBQ,GAChCR,EAAO,0BAA2BI,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdf,EAAO,kBAAmBkB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,GAPC,CAQD,CA5BDjB,EAAO,6BADPU,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJf,EAAO,2BAA4Be,EAAMM,SAClChB,EAAMU,KAGdf,EAAO,0CADPM,GAAS,EACgDG,GACpDC,EAAM,EACHG,IAEHP,IAAUG,GACdT,EAAO,qCACAK,EAAM,KAAMF,SAFpB,EAIA,CACF,CCzCA,SAASmB,EAAShC,EAASc,GAC1B,IAAIf,EACAkC,EACAC,EAGJ,GADAnC,EAAO,CAAA,EACFoC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMnC,EAAUC,EAAMC,GAErB,MAAMiC,EAEPC,EAAIpB,CACN,MACEoB,EAAIlC,EAEL,IAAMoC,EAAYF,GACjB,MAAM,IAAI5B,UAAWC,EAAQ,WAAY2B,IAU1C,YARqB,IAAhBnC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ6B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIN,UAAWC,EAAQ,WAAYK,IAE1C,IAAMwB,EAAYrB,GACjB,MAAM,IAAIT,UAAWC,EAAQ,WAAYQ,IAE1C,OAAOP,EAAOI,EAAY2B,EAASxC,EAAMmC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,EACZ,GACD,CACF,CC1EA,SAASyB,EAAkB1B,EAAY2B,EAASvC,EAASc,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAShC,EAATgC,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAShC,EAASc,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,EAC/C,CClBA0B,EAAAC,EAAA,UAAAV"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 60d2235..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From e6a78f5c724bb94db57c2f77b120efb5e9862e98 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 23 Sep 2023 17:43:49 +0000 Subject: [PATCH 067/147] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 783 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 47 +- benchmark/benchmark.factory.js | 73 - benchmark/benchmark.js | 160 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 224 - docs/types/test.ts | 166 - examples/index.js | 55 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 164 - lib/index.js | 77 - lib/limit.js | 142 - lib/main.js | 95 - lib/validate.js | 80 - package.json | 64 +- stats.html | 6177 +++++++++++++++++++++ test/test.factory.js | 1095 ---- test/test.js | 38 - test/test.main.js | 1035 ---- test/test.validate.js | 181 - 47 files changed, 6208 insertions(+), 6847 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/limit.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1e08946..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 663f5df..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 45a5053..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '37 1 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 91f2b93..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,783 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -458,7 +457,7 @@ reduceRightAsync( files, acc, read, done ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -526,11 +525,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right +[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right/tree/esm -[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce +[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/tree/esm diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 46d8b83..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var reduceRightAsync; - var arr; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - reduceRightAsync = factory( onItem ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - var acc; - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 6ad0714..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var reduceRightAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=false', function benchmark( b ) { - var opts; - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'series': false - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var arr; - var len; - var acc; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'limit': 3 - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index acfc6d6..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right" -%% click B href "https://github.com/stdlib-js/utils-async-reduce-right/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-reduce-right/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-reduce-right/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-reduce-right/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right -[production-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 47a072e..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import reduceRightAsync from '../docs/types/index'; -export = reduceRightAsync; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 530ca4d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var c=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var x=c(function(U,O){ -var R=require('@stdlib/assert-is-plain-object/dist'),h=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,k=require('@stdlib/assert-is-positive-integer/dist').isPrimitive,d=require('@stdlib/error-tools-fmtprodmsg/dist');function I(e,r){return R(r)?(h(r,"thisArg")&&(e.thisArg=r.thisArg),h(r,"series")&&(e.series=r.series,!j(e.series))?new TypeError(d('1RZ2o',"series",e.series)):h(r,"limit")&&(e.limit=r.limit,!k(e.limit))?new TypeError(d('1RZ3P',"limit",e.limit)):null):new TypeError(d('1RZ2V',r));}O.exports=I -});var P=c(function(W,E){ -var J=require("debug"),a=J("reduce-right-async:limit");function L(e,r,i,t,s){var f,m,v,n,u,g;if(n=e.length,a("Collection length: %d",n),n===0)return a("Finished processing a collection."),s(null,r);for(n0&&o();function o(){u-=1,a("Collection element %d: %s.",u,JSON.stringify(e[u])),t.length===3?t.call(i.thisArg,r,e[u],l):t.length===4?t.call(i.thisArg,r,e[u],u,l):t.call(i.thisArg,r,e[u],u,e,l);function l(w,A){if(!m){if(w)return m=!0,b(w);a("Accumulator: %s",JSON.stringify(A)),r=A,b()}}}function b(l){if(l)return a("Encountered an error: %s",l.message),s(l);if(f+=1,a("Processed %d of %d collection elements.",f,n),u>0)return o();if(f===n)return a("Finished processing a collection."),s(null,r)}}E.exports=L -});var q=c(function(X,F){ -var T=require('@stdlib/assert-is-function/dist'),S=require('@stdlib/assert-is-collection/dist'),y=require('@stdlib/error-tools-fmtprodmsg/dist'),B=require('@stdlib/constants-float64-pinf/dist'),z=x(),D=P();function G(e,r){var i,t,s;if(i={},arguments.length>1){if(t=z(i,e),t)throw t;s=r}else s=e;if(!T(s))throw new TypeError(y('1RZ3q',s));return i.series===void 0&&i.limit===void 0&&(i.series=!0),i.series?i.limit=1:i.limit||(i.limit=B),f;function f(m,v,n){if(!S(m))throw new TypeError(y('1RZAh',m));if(!T(n))throw new TypeError(y('1RZ3q',n));return D(m,v,i,s,u);function u(g,o){if(g)return n(g);n(null,o)}}}F.exports=G -});var N=c(function(Y,C){ -var p=q();function H(e,r,i,t,s){if(arguments.length<5)return p(i)(e,r,t);p(i,t)(e,r,s)}C.exports=H -});var K=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),V=N(),M=q();K(V,"factory",M);module.exports=V; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index acb9d67..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/limit.js", "../lib/factory.js", "../lib/main.js", "../lib/index.js"], - "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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\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 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 to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\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 === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, 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 ( !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, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\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* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nmodule.exports = reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' );\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, 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"], - "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,0BAA2B,EAkB/C,SAASE,EAAOC,EAAYC,EAAKC,EAAMC,EAAKC,EAAO,CAClD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMR,EAAW,OACjBF,EAAO,wBAAyBU,CAAI,EAE/BA,IAAQ,EACZ,OAAAV,EAAO,mCAAoC,EACpCM,EAAM,KAAMH,CAAI,EAYxB,IAVKO,EAAMN,EAAK,MACfK,EAAMC,EAEND,EAAML,EAAK,MAEZJ,EAAO,wBAAyBS,CAAI,EACpCT,EAAO,0BAA2BK,EAAI,MAAO,EAE7CE,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVE,EAAK,EAQP,SAASA,GAAO,CACfF,GAAO,EACPX,EAAO,6BAA8BW,EAAK,KAAK,UAAWT,EAAYS,CAAI,CAAE,CAAE,EACzEN,EAAI,SAAW,EACnBA,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGG,CAAG,EACxCT,EAAI,SAAW,EAC1BA,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGA,EAAKG,CAAG,EAExDT,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGA,EAAKT,EAAYY,CAAG,EAUrE,SAASA,EAAIC,EAAOC,EAAS,CAC5B,GAAK,CAAAR,EAIL,IAAKO,EACJ,OAAAP,EAAM,GACCS,EAAMF,CAAM,EAEpBf,EAAO,kBAAmB,KAAK,UAAWgB,CAAO,CAAE,EACnDb,EAAMa,EACNC,EAAK,EACN,CACD,CASA,SAASA,EAAMF,EAAQ,CACtB,GAAKA,EACJ,OAAAf,EAAO,2BAA4Be,EAAM,OAAQ,EAC1CT,EAAMS,CAAM,EAIpB,GAFAR,GAAS,EACTP,EAAO,0CAA2CO,EAAOG,CAAI,EACxDC,EAAM,EACV,OAAOE,EAAK,EAEb,GAAKN,IAAUG,EACd,OAAAV,EAAO,mCAAoC,EACpCM,EAAM,KAAMH,CAAI,CAEzB,CACD,CAKAL,EAAO,QAAUG,IC7IjB,IAAAiB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,gCAAiC,EACjDC,EAAW,IACXC,EAAQ,IAoEZ,SAASC,EAASC,EAASC,EAAM,CAChC,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,CAACP,EAAYW,CAAE,EACnB,MAAM,IAAI,UAAWT,EAAQ,mEAAoES,CAAE,CAAE,EAEtG,OAAKF,EAAK,SAAW,QAAUA,EAAK,QAAU,SAC7CA,EAAK,OAAS,IAEVA,EAAK,OACTA,EAAK,MAAQ,EACDA,EAAK,QACjBA,EAAK,MAAQN,GAEPS,EAaP,SAASA,EAAkBC,EAAYC,EAASC,EAAO,CACtD,GAAK,CAACd,EAAcY,CAAW,EAC9B,MAAM,IAAI,UAAWX,EAAQ,sEAAuEW,CAAW,CAAE,EAElH,GAAK,CAACb,EAAYe,CAAK,EACtB,MAAM,IAAI,UAAWb,EAAQ,mEAAoEa,CAAK,CAAE,EAEzG,OAAOV,EAAOQ,EAAYC,EAASL,EAAME,EAAGK,CAAK,EAUjD,SAASA,EAAMC,EAAOC,EAAM,CAC3B,GAAKD,EACJ,OAAOF,EAAME,CAAM,EAEpBF,EAAM,KAAMG,CAAI,CACjB,CACD,CACD,CAKAnB,EAAO,QAAUO,ICnKjB,IAAAa,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,IA8Dd,SAASC,EAAkBC,EAAYC,EAASC,EAASC,EAAKC,EAAO,CACpE,GAAK,UAAU,OAAS,EACvB,OAAON,EAASI,CAAQ,EAAGF,EAAYC,EAASE,CAAI,EAErDL,EAASI,EAASC,CAAI,EAAGH,EAAYC,EAASG,CAAK,CACpD,CAKAP,EAAO,QAAUE,IC9BjB,IAAIM,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "isPositiveInteger", "format", "validate", "opts", "options", "require_limit", "__commonJSMin", "exports", "module", "logger", "debug", "limit", "collection", "acc", "opts", "fcn", "done", "count", "flg", "lim", "len", "idx", "i", "next", "cb", "error", "result", "clbk", "require_factory", "__commonJSMin", "exports", "module", "isFunction", "isCollection", "format", "PINF", "validate", "limit", "factory", "options", "fcn", "opts", "err", "f", "reduceRightAsync", "collection", "initial", "done", "clbk", "error", "acc", "require_main", "__commonJSMin", "exports", "module", "factory", "reduceRightAsync", "collection", "initial", "options", "fcn", "done", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3f22669..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,224 +0,0 @@ - -{{alias}}( collection, initial, [options,] reducer, done ) - Applies a function against an accumulator and each element in a collection - and returns the accumulated result, iterating from right to left. - - When invoked, `reducer` is provided a maximum of five arguments: - - - `accumulator`: accumulated value - - `value`: collection value - - `index`: collection index - - `collection`: the input collection - - `next`: a callback to be invoked after processing a collection `value` - - The actual number of provided arguments depends on function length. If - `reducer` accepts three arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `next` - - If `reducer` accepts four arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `index` - - `next` - - For every other `reducer` signature, `reducer` is provided all five - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `accumulator`: accumulated value - - If a provided function calls the `next` callback with a truthy `error` - argument, the function suspends execution and immediately calls the `done` - callback for subsequent `error` handling. - - Execution is *not* guaranteed to be asynchronous. To guarantee asynchrony, - 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`). - - The function does not support dynamic collection resizing. - - If provided an empty collection, the function invokes the `done` callback - with the `initial` value as the second argument. - - The function does not skip `undefined` elements. - - When processing collection elements concurrently, *beware* of race - conditions when updating an accumulator. This is especially true when an - accumulator is a primitive (e.g., a number). In general, prefer object - accumulators. - - Parameters - ---------- - collection: Array|TypedArray|Object - Input collection over which to iterate. If provided an object, the - object must be array-like (excluding strings and functions). - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - reducer: Function - The function to invoke for each element in a collection. - - done: Function - A callback invoked either upon processing all collection elements or - upon encountering an error. - - Examples - -------- - // Basic usage: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, fcn, done ) - 3000 - 2500 - 1000 - 6500 - - // Limit number of concurrent invocations: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'limit': 2 }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 2500 - 3000 - 1000 - 6500 - - // Process concurrently: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'series': false }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 1000 - 2500 - 3000 - 6500 - - -{{alias}}.factory( [options,] fcn ) - Returns a function which applies a function against an accumulator and each - element in a collection and returns the accumulated result, iterating from - right to left. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - fcn: Function - The function to invoke for each element in a collection. - - Returns - ------- - out: Function - A function which invokes a function for each element in a collection. - - Examples - -------- - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > var opts = { 'series': false }; - > var f = {{alias}}.factory( opts, fcn ); - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > f( arr, acc, done ) - 1000 - 2500 - 3000 - 6500 - > acc = { 'sum': 0 }; - > arr = [ 1000, 1500, 2000 ]; - > f( arr, acc, done ) - 1000 - 1500 - 2000 - 4500 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index f0001b3..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,166 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unsafe-any */ - -import reduceRightAsync = require( './index' ); - -const reducer = ( acc: any, value: number, index: number, next: Function ) => { - acc.sum += value; - if ( index === void 0 ) { - throw new Error( '`index` is missing.' ); - } - next( null, acc ); -}; - -const done = ( error: Error | null, acc: any ) => { - if ( error ) { - throw error; - } - if ( acc === void 0 ) { - throw new Error( '`acc` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( 2, acc, reducer, done ); // $ExpectError - reduceRightAsync( false, acc, reducer, done ); // $ExpectError - reduceRightAsync( true, acc, reducer, done ); // $ExpectError - reduceRightAsync( {}, acc, reducer, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a predicate argument which is not a predicate function... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 2, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, false, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, true, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 'abc', done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, [], done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a done callback argument which is not a function having a supported signature... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 2 ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, false ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, true ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 'abc' ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, {} ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, [] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const acc = { 'sum': 0 }; - reduceRightAsync(); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, reducer, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - reduceRightAsync.factory( reducer ); // $ExpectType FactoryFunction - reduceRightAsync.factory( { 'series': true }, reducer ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - reduceRightAsync.factory( [], reducer ); // $ExpectError - reduceRightAsync.factory( 123, reducer ); // $ExpectError - reduceRightAsync.factory( 'abc', reducer ); // $ExpectError - reduceRightAsync.factory( false, reducer ); // $ExpectError - reduceRightAsync.factory( true, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not a predicate function... -{ - reduceRightAsync.factory( {} ); // $ExpectError - reduceRightAsync.factory( true ); // $ExpectError - reduceRightAsync.factory( false ); // $ExpectError - reduceRightAsync.factory( {}, 123 ); // $ExpectError - reduceRightAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1( 12, acc, done ); // $ExpectError - fcn1( true, acc, done ); // $ExpectError - fcn1( false, acc, done ); // $ExpectError - fcn1( {}, acc, done ); // $ExpectError - - fcn1( [ 3000, 2500, 1000 ], acc, 12 ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, true ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, false ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, '5' ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, {} ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, [] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1(); // $ExpectError - fcn1( [ 3000, 2500, 1000 ] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - reduceRightAsync.factory( { 'limit': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': true }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': false }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - reduceRightAsync.factory( { 'series': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': 12 }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - reduceRightAsync.factory(); // $ExpectError - reduceRightAsync.factory( {}, reducer, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index dd64345..0000000 --- a/examples/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var resolve = require( 'path' ).resolve; -var readFile = require( '@stdlib/fs-read-file' ); -var reduceRightAsync = require( './../lib' ); - -var files = [ - resolve( __dirname, '..', 'package.json' ), - resolve( __dirname, '..', 'README.md' ) -]; - -function done( error, acc ) { - if ( error ) { - throw error; - } - console.log( acc.count ); -} - -function read( acc, file, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( file, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( null, acc ); - } - acc.count += 1; - next( null, acc ); - } -} - -var acc = { - 'count': 0 -}; -reduceRightAsync( files, acc, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 80786cf..2657f80 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..db292f7 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.0-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.0-esm/index.mjs";import{isPrimitive as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.1.0-esm/index.mjs";function m(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("1RZ2o,GE","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!d(e.limit))?new TypeError(r("1RZ3P,Fv","limit",e.limit)):null):new TypeError(r("1RZ2V,FD",t))}function c(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){if(this instanceof e){var i=[null];i.push.apply(i,arguments);var r=Function.bind.apply(t,i);return new r}return t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var f=c(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function p(e,t,i,r,s){var n,o,l,d,m,c;if(d=e.length,f("Collection length: %d",d),0===d)return f("Finished processing a collection."),s(null,t);for(l=d0&&p();function p(){function s(e,i){if(!o){if(e)return o=!0,u(e);f("Accumulator: %s",JSON.stringify(i)),t=i,u()}}f("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function u(e){return e?(f("Encountered an error: %s",e.message),s(e)):(f("Processed %d of %d collection elements.",n+=1,d),m>0?p():n===d?(f("Finished processing a collection."),s(null,t)):void 0)}}function u(e,n){var o,l,d;if(o={},arguments.length>1){if(l=m(o,e))throw l;d=n}else d=e;if(!t(d))throw new TypeError(r("1RZ3q,JV",d));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=s),c;function c(e,s,n){if(!i(e))throw new TypeError(r("1RZAh,O3",e));if(!t(n))throw new TypeError(r("1RZ3q,JV",n));return p(e,s,o,d,(function(e,t){if(e)return n(e);n(null,t)}))}}function a(e,t,i,r,s){if(arguments.length<5)return u(i)(e,t,r);u(i,r)(e,t,s)}e(a,"factory",u);export{a as default,u as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..db85f46 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '1RZ2V,FD', 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( '1RZ2o,GE', '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( '1RZ3P,Fv', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RZ3q,JV', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '1RZAh,O3', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RZ3q,JV', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","logger","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly","main"],"mappings":";;04BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,WAAY,SAAUR,EAAKK,SAGtDF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,WAAY,QAASR,EAAKS,QAGnD,MAjBC,IAAIF,UAAWC,EAAQ,WAAYP,GAkB5C,8eC/CIU,uDAAQC,CAAQ,4BAkBpB,SAASH,EAAOI,EAAYC,EAAKd,EAAMe,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMP,EAAWU,OACjBZ,EAAO,wBAAyBS,GAEnB,IAARA,EAEJ,OADAT,EAAO,qCACAK,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAEZE,EAAO,wBAAyBQ,GAChCR,EAAO,0BAA2BI,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdf,EAAO,kBAAmBkB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,GAPC,CAQD,CA5BDjB,EAAO,6BADPU,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJf,EAAO,2BAA4Be,EAAMM,SAClChB,EAAMU,KAGdf,EAAO,0CADPM,GAAS,EACgDG,GACpDC,EAAM,EACHG,IAEHP,IAAUG,GACdT,EAAO,qCACAK,EAAM,KAAMF,SAFpB,EAIA,CACF,CCzCA,SAASmB,EAAShC,EAASc,GAC1B,IAAIf,EACAkC,EACAC,EAGJ,GADAnC,EAAO,CAAA,EACFoC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMnC,EAAUC,EAAMC,GAErB,MAAMiC,EAEPC,EAAIpB,CACN,MACEoB,EAAIlC,EAEL,IAAMoC,EAAYF,GACjB,MAAM,IAAI5B,UAAWC,EAAQ,WAAY2B,IAU1C,YARqB,IAAhBnC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ6B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIN,UAAWC,EAAQ,WAAYK,IAE1C,IAAMwB,EAAYrB,GACjB,MAAM,IAAIT,UAAWC,EAAQ,WAAYQ,IAE1C,OAAOP,EAAOI,EAAY2B,EAASxC,EAAMmC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,EACZ,GACD,CACF,CC1EA,SAASyB,EAAkB1B,EAAY2B,EAASvC,EAASc,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAShC,EAATgC,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAShC,EAASc,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,EAC/C,CClBA0B,EAAAC,EAAA,UAAAV"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 1cd0d47..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,164 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var validate = require( './validate.js' ); -var limit = require( './limit.js' ); - - -// MAIN // - -/** -* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} last argument must be a function -* @returns {Function} function which invokes the provided function once for each element in a collection -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error, data ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var opts = { -* 'series': false -* }; -* -* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: -* var reduceRightAsync = factory( opts, read ); -* -* // Create a collection over which to iterate: -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* // Define a callback which handles errors: -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* // Run `read` for each element in `files`: -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, done ); -*/ -function factory( options, fcn ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = fcn; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '1RZ3q,JV', f ) ); - } - if ( opts.series === void 0 && opts.limit === void 0 ) { - opts.series = true; - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return reduceRightAsync; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * @private - * @param {Collection} collection - input collection - * @param {*} initial - initial value - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be a collection - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function reduceRightAsync( collection, initial, done ) { - if ( !isCollection( collection ) ) { - throw new TypeError( format( '1RZAh,O3', collection ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '1RZ3q,JV', done ) ); - } - return limit( collection, initial, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {*} [acc] - accumulated value - * @returns {void} - */ - function clbk( error, acc ) { - if ( error ) { - return done( error ); - } - done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ae657ff..0000000 --- a/lib/index.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* @module @stdlib/utils-async-reduce-right -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' ); -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/limit.js b/lib/limit.js deleted file mode 100644 index cdb60af..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); - - -// VARIABLES // - -var debug = logger( 'reduce-right-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each element in a collection, limiting the number of concurrently pending functions and iterating from right to left. -* -* @private -* @param {Collection} collection - input collection -* @param {*} acc - initial value -* @param {Options} opts - function options -* @param {*} [opts.thisArg] - execution context -* @param {PositiveInteger} [opts.limit] - maximum number of pending function invocations -* @param {Function} fcn - function to invoke -* @param {Callback} done - function to invoke upon completion or upon encountering an error -* @returns {void} -*/ -function limit( collection, acc, opts, fcn, done ) { - var count; - var flg; - var lim; - var len; - var idx; - var i; - - len = collection.length; - debug( 'Collection length: %d', len ); - - if ( len === 0 ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - count = 0; - idx = len; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all collection elements... - if ( idx > 0 ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next element in a collection. - * - * @private - */ - function next() { - idx -= 1; - debug( 'Collection element %d: %s.', idx, JSON.stringify( collection[ idx ] ) ); - if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], cb ); - } else if ( fcn.length === 4 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, cb ); - } else { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len - } - /** - * Callback invoked once a provided function finishes processing a collection element. - * - * @private - * @param {*} [error] - error - * @param {*} [result] - accumulation result - * @returns {void} - */ - function cb( error, result ) { - if ( flg ) { - // Prevent further processing of collection elements: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Accumulator: %s', JSON.stringify( result ) ); - acc = result; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next collection element. - * - * @private - * @param {*} [error] - error - * @returns {void} - */ - function clbk( error ) { - if ( error ) { - debug( 'Encountered an error: %s', error.message ); - return done( error ); - } - count += 1; - debug( 'Processed %d of %d collection elements.', count, len ); - if ( idx > 0 ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index c8b0d0f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param {Collection} collection - input collection -* @param {*} initial - initial value -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} second-to-last argument must be a function -* @throws {TypeError} last argument must be a function -* @returns {void} -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -function reduceRightAsync( collection, initial, options, fcn, done ) { - if ( arguments.length < 5 ) { - return factory( options )( collection, initial, fcn ); - } - factory( options, fcn )( collection, initial, done ); -} - - -// EXPORTS // - -module.exports = reduceRightAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index c90c17f..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @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 -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'thisArg': {}, -* 'series': false, -* 'limit': 10 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '1RZ2V,FD', options ) ); - } - if ( hasOwnProp( options, 'thisArg' ) ) { - opts.thisArg = options.thisArg; - } - if ( hasOwnProp( options, 'series' ) ) { - opts.series = options.series; - if ( !isBoolean( opts.series ) ) { - return new TypeError( format( '1RZ2o,GE', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '1RZ3P,Fv', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 9d271e6..d4f9525 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,43 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.1.0", - "@stdlib/assert-is-boolean": "^0.1.0", - "@stdlib/assert-is-collection": "^0.1.0", - "@stdlib/assert-is-function": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.0", - "@stdlib/assert-is-positive-integer": "^0.1.0", - "@stdlib/constants-float64-pinf": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.0", - "@stdlib/types": "^0.1.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.0", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/bench": "^0.1.0", - "@stdlib/constants-float64-eps": "^0.1.0", - "@stdlib/fs-read-file": "^0.1.0", - "@stdlib/utils-noop": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..598d999 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 8244931..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1095 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( {}, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, next ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - factory( opts, next ); - }; - } -}); - -tape( 'the function returns a function (no options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided a collection (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a collection (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (1 argument)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (2 arguments)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with five arguments', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn() { - var value; - var next; - var acc; - var k; - - acc = arguments[ 0 ]; - value = arguments[ 1 ]; - k = arguments[ 2 ]; - next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( k, i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the returned function supports processing collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements concurrently', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 100, 250, 300 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements sequentially (limit = 1)', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of collection elements which are processed at any one time', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 250, 300, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 250, 100, 300 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var reduceRightAsync; - var arr; - - reduceRightAsync = factory( fcn ); - arr = []; - - reduceRightAsync( arr, 0, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var reduceRightAsync; - var obj; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = []; - obj = {}; - reduceRightAsync( arr, obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - i = 0; - - reduceRightAsync( arr, {}, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, acc ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the returned function does not skip empty elements', function test( t ) { - var reduceRightAsync; - var expected; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index f273a40..0000000 --- a/test/test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof reduceRightAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 1893240..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1035 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a collection', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (no options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, next, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, 0 ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - reduceRightAsync( [ 1, 2, 3 ], 0, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (1 argument)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (2 arguments)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with five arguments', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn() { - var next; - var acc; - var v; - - next = arguments[ 4 ]; - acc = arguments[ 0 ]; - v = arguments[ 1 ]; - - i -= 1; - j += 1; - - t.strictEqual( v, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, v ); - - function onTimeout() { - acc.sum += v; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'by default, the function processes collection elements sequentially', function test( t ) { - var values; - var count; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements concurrently', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 100, 250, 300 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': true - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially (limit = 1)', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var arr; - var ctx; - - arr = [ 3, 2, 1 ]; - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 3, 2, 1 ]; - opts = { - 'series': true - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 250, 100, 300 ]; - opts = { - 'limit': 2 - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var arr = []; - reduceRightAsync( arr, 0, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var arr = []; - var obj = {}; - - reduceRightAsync( arr, obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - arr = [ 3, 2, 1 ]; - i = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, value ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the function does not skip empty elements', function test( t ) { - var expected; - var arr; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, fcn, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 7660838..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,181 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `limit` option which is not a positive integer', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - -5, - 0, - 3.14, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'limit': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `series` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'series': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function accepts any value for the `thisArg` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'thisArg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err, null, 'returns null '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'thisArg': {}, - 'series': false, - 'limit': 10 - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From 67c80a06093b8178fbb4dc740eab715a43f205a4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 23 Sep 2023 18:11:49 +0000 Subject: [PATCH 068/147] Update README.md for ESM bundle v0.1.0 --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9c530bd..fd5f6c4 100644 --- a/README.md +++ b/README.md @@ -52,13 +52,13 @@ limitations under the License. ## Usage ```javascript -import reduceRightAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-reduce-right@esm/index.mjs'; +import reduceRightAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-reduce-right@v0.1.0-esm/index.mjs'; ``` You can also import the following named exports from the package: ```javascript -import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-reduce-right@esm/index.mjs'; +import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-reduce-right@v0.1.0-esm/index.mjs'; ``` #### reduceRightAsync( collection, initial, \[options,] reducer, done ) @@ -381,7 +381,7 @@ The function accepts the same `options` as `reduceRightAsync()`. var resolve = require( 'path' ).resolve; import readFile from 'https://cdn.jsdelivr.net/gh/stdlib-js/fs-read-file@esm/index.mjs'; -import reduceRightAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-reduce-right@esm/index.mjs'; +import reduceRightAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-reduce-right@v0.1.0-esm/index.mjs'; var files = [ resolve( __dirname, 'package.json' ), From fbd0139c384650695cb219169fc049b8614f4488 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 23 Sep 2023 18:11:50 +0000 Subject: [PATCH 069/147] Auto-generated commit --- README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index fd5f6c4..4def6c1 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import reduceRightAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-reduce-right@esm/index.mjs'; +``` +The previous example will load the latest bundled code from the esm branch. Alternatively, you may load a specific version by loading the file from one of the [tagged bundles](https://github.com/stdlib-js/utils-async-reduce-right/tags). For example, + ```javascript import reduceRightAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-reduce-right@v0.1.0-esm/index.mjs'; ``` @@ -58,7 +63,7 @@ import reduceRightAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async- You can also import the following named exports from the package: ```javascript -import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-reduce-right@v0.1.0-esm/index.mjs'; +import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-reduce-right@esm/index.mjs'; ``` #### reduceRightAsync( collection, initial, \[options,] reducer, done ) @@ -381,7 +386,7 @@ The function accepts the same `options` as `reduceRightAsync()`. var resolve = require( 'path' ).resolve; import readFile from 'https://cdn.jsdelivr.net/gh/stdlib-js/fs-read-file@esm/index.mjs'; -import reduceRightAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-reduce-right@v0.1.0-esm/index.mjs'; +import reduceRightAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-reduce-right@esm/index.mjs'; var files = [ resolve( __dirname, 'package.json' ), From 25e887e43cac4b03d53c749c289bd7df7f6bdba6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Oct 2023 07:58:29 +0000 Subject: [PATCH 070/147] Transform error messages --- lib/factory.js | 8 ++++---- lib/validate.js | 8 ++++---- package.json | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 1125052..1cd0d47 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -22,7 +22,7 @@ var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var PINF = require( '@stdlib/constants-float64-pinf' ); var validate = require( './validate.js' ); var limit = require( './limit.js' ); @@ -109,7 +109,7 @@ function factory( options, fcn ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '1RZ3q,JV', f ) ); } if ( opts.series === void 0 && opts.limit === void 0 ) { opts.series = true; @@ -134,10 +134,10 @@ function factory( options, fcn ) { */ function reduceRightAsync( collection, initial, done ) { if ( !isCollection( collection ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a collection. Value: `%s`.', collection ) ); + throw new TypeError( format( '1RZAh,O3', collection ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '1RZ3q,JV', done ) ); } return limit( collection, initial, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index 9ba927e..c90c17f 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,7 +54,7 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '1RZ2V,FD', options ) ); } if ( hasOwnProp( options, 'thisArg' ) ) { opts.thisArg = options.thisArg; @@ -62,13 +62,13 @@ function validate( opts, options ) { if ( hasOwnProp( options, 'series' ) ) { opts.series = options.series; if ( !isBoolean( opts.series ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'series', opts.series ) ); + return new TypeError( format( '1RZ2o,GE', 'series', opts.series ) ); } } if ( hasOwnProp( options, 'limit' ) ) { opts.limit = options.limit; if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'limit', opts.limit ) ); + return new TypeError( format( '1RZ3P,Fv', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index 74b1a81..9d271e6 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-plain-object": "^0.1.0", "@stdlib/assert-is-positive-integer": "^0.1.0", "@stdlib/constants-float64-pinf": "^0.1.0", - "@stdlib/string-format": "^0.1.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.0", "@stdlib/types": "^0.1.0", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.0", "debug": "^2.6.9" From f9cbfedca3b33d91b86e5a84ff502b044d7fe604 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 2 Oct 2023 13:00:08 +0000 Subject: [PATCH 071/147] Remove files --- index.d.ts | 410 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6592 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 2657f80..0000000 --- a/index.d.ts +++ /dev/null @@ -1,410 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Execution context. - */ - thisArg?: ThisParameterType>; - - /** - * The maximum number of pending invocations at any one time. - */ - limit?: number; - - /** - * Boolean indicating whether to sequentially invoke the reducer function for each `collection` element. If `true`, the function sets `options.limit=1`. Default: true. - */ - series?: boolean; -} - -/** -* Callback function. -*/ -type Nullary = () => void; - -/** -* Callback function. -* -* @param error - encountered error or null -*/ -type Unary = ( error: Error | null ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Binary = ( error: Error | null, accumulator: U ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param next - a callback to be invoked after processing a collection `value` -*/ -type TernaryReducer = ( this: V, accumulator: U, value: T, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuaternaryReducer = ( this: V, accumulator: U, value: T, index: number, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuinaryReducer = ( this: V, accumulator: U, value: T, index: number, collection: Collection, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type Reducer = TernaryReducer | QuaternaryReducer | QuinaryReducer; - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result. -* -* @param collection - input collection -* @param initial - initial value -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( collection: Collection, initial: U, done: Callback ) => void; - -/** -* Interface for `reduceRightAsync`. -*/ -interface ReduceRightAsync { - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, {}, read, done ); - */ - ( collection: Collection, initial: U, options: Options, reducer: Reducer, done: Callback ): void; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, read, done ); - */ - ( collection: Collection, initial: U, reducer: Reducer, done: Callback ): void; // tslint:disable-line:no-unnecessary-generics - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @throws must provide valid options - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var opts = { - * 'series': false - * }; - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( opts, read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( options: Options, reducer: Reducer ): FactoryFunction; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param reducer - function to invoke for each element in a collection - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( reducer: Reducer ): FactoryFunction; // tslint:disable-line:no-unnecessary-generics -} - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param collection - input collection -* @param initial - initial value -* @param options - function options -* @param options.thisArg - execution context -* @param options.limit - maximum number of pending invocations at any one time -* @param 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 (default: true) -* @param reducer - function to invoke for each element in a collection -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( `@stdlib/fs/read-file` ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -declare var reduceRightAsync: ReduceRightAsync; - - -// EXPORTS // - -export = reduceRightAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index db292f7..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.0-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.0-esm/index.mjs";import{isPrimitive as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.1.0-esm/index.mjs";function m(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("1RZ2o,GE","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!d(e.limit))?new TypeError(r("1RZ3P,Fv","limit",e.limit)):null):new TypeError(r("1RZ2V,FD",t))}function c(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){if(this instanceof e){var i=[null];i.push.apply(i,arguments);var r=Function.bind.apply(t,i);return new r}return t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var f=c(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function p(e,t,i,r,s){var n,o,l,d,m,c;if(d=e.length,f("Collection length: %d",d),0===d)return f("Finished processing a collection."),s(null,t);for(l=d0&&p();function p(){function s(e,i){if(!o){if(e)return o=!0,u(e);f("Accumulator: %s",JSON.stringify(i)),t=i,u()}}f("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function u(e){return e?(f("Encountered an error: %s",e.message),s(e)):(f("Processed %d of %d collection elements.",n+=1,d),m>0?p():n===d?(f("Finished processing a collection."),s(null,t)):void 0)}}function u(e,n){var o,l,d;if(o={},arguments.length>1){if(l=m(o,e))throw l;d=n}else d=e;if(!t(d))throw new TypeError(r("1RZ3q,JV",d));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=s),c;function c(e,s,n){if(!i(e))throw new TypeError(r("1RZAh,O3",e));if(!t(n))throw new TypeError(r("1RZ3q,JV",n));return p(e,s,o,d,(function(e,t){if(e)return n(e);n(null,t)}))}}function a(e,t,i,r,s){if(arguments.length<5)return u(i)(e,t,r);u(i,r)(e,t,s)}e(a,"factory",u);export{a as default,u as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index db85f46..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '1RZ2V,FD', 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( '1RZ2o,GE', '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( '1RZ3P,Fv', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RZ3q,JV', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '1RZAh,O3', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RZ3q,JV', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","logger","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly","main"],"mappings":";;04BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,WAAY,SAAUR,EAAKK,SAGtDF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,WAAY,QAASR,EAAKS,QAGnD,MAjBC,IAAIF,UAAWC,EAAQ,WAAYP,GAkB5C,8eC/CIU,uDAAQC,CAAQ,4BAkBpB,SAASH,EAAOI,EAAYC,EAAKd,EAAMe,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMP,EAAWU,OACjBZ,EAAO,wBAAyBS,GAEnB,IAARA,EAEJ,OADAT,EAAO,qCACAK,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAEZE,EAAO,wBAAyBQ,GAChCR,EAAO,0BAA2BI,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdf,EAAO,kBAAmBkB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,GAPC,CAQD,CA5BDjB,EAAO,6BADPU,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJf,EAAO,2BAA4Be,EAAMM,SAClChB,EAAMU,KAGdf,EAAO,0CADPM,GAAS,EACgDG,GACpDC,EAAM,EACHG,IAEHP,IAAUG,GACdT,EAAO,qCACAK,EAAM,KAAMF,SAFpB,EAIA,CACF,CCzCA,SAASmB,EAAShC,EAASc,GAC1B,IAAIf,EACAkC,EACAC,EAGJ,GADAnC,EAAO,CAAA,EACFoC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMnC,EAAUC,EAAMC,GAErB,MAAMiC,EAEPC,EAAIpB,CACN,MACEoB,EAAIlC,EAEL,IAAMoC,EAAYF,GACjB,MAAM,IAAI5B,UAAWC,EAAQ,WAAY2B,IAU1C,YARqB,IAAhBnC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ6B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIN,UAAWC,EAAQ,WAAYK,IAE1C,IAAMwB,EAAYrB,GACjB,MAAM,IAAIT,UAAWC,EAAQ,WAAYQ,IAE1C,OAAOP,EAAOI,EAAY2B,EAASxC,EAAMmC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,EACZ,GACD,CACF,CC1EA,SAASyB,EAAkB1B,EAAY2B,EAASvC,EAASc,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAShC,EAATgC,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAShC,EAASc,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,EAC/C,CClBA0B,EAAAC,EAAA,UAAAV"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 598d999..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From f471ef2b87c50fedadde4a015f2b3fdc3085408b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 2 Oct 2023 13:00:52 +0000 Subject: [PATCH 072/147] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 247 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 47 +- benchmark/benchmark.factory.js | 73 - benchmark/benchmark.js | 160 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 224 - docs/types/test.ts | 166 - examples/index.js | 55 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 164 - lib/index.js | 77 - lib/limit.js | 142 - lib/main.js | 95 - lib/validate.js | 80 - package.json | 64 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 38 - test/test.factory.js | 1095 ---- test/test.js | 38 - test/test.main.js | 1035 ---- test/test.validate.js | 181 - 49 files changed, 6208 insertions(+), 6944 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/limit.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index f495120..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-10-01T02:49:45.866Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1e08946..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 5358060..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 372758f..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '37 1 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -458,7 +457,7 @@ reduceRightAsync( files, acc, read, done ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -526,11 +525,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right +[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right/tree/esm -[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce +[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/tree/esm diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 46d8b83..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var reduceRightAsync; - var arr; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - reduceRightAsync = factory( onItem ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - var acc; - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 6ad0714..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var reduceRightAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=false', function benchmark( b ) { - var opts; - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'series': false - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var arr; - var len; - var acc; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'limit': 3 - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index acfc6d6..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right" -%% click B href "https://github.com/stdlib-js/utils-async-reduce-right/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-reduce-right/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-reduce-right/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-reduce-right/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right -[production-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 47a072e..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import reduceRightAsync from '../docs/types/index'; -export = reduceRightAsync; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 530ca4d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var c=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var x=c(function(U,O){ -var R=require('@stdlib/assert-is-plain-object/dist'),h=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,k=require('@stdlib/assert-is-positive-integer/dist').isPrimitive,d=require('@stdlib/error-tools-fmtprodmsg/dist');function I(e,r){return R(r)?(h(r,"thisArg")&&(e.thisArg=r.thisArg),h(r,"series")&&(e.series=r.series,!j(e.series))?new TypeError(d('1RZ2o',"series",e.series)):h(r,"limit")&&(e.limit=r.limit,!k(e.limit))?new TypeError(d('1RZ3P',"limit",e.limit)):null):new TypeError(d('1RZ2V',r));}O.exports=I -});var P=c(function(W,E){ -var J=require("debug"),a=J("reduce-right-async:limit");function L(e,r,i,t,s){var f,m,v,n,u,g;if(n=e.length,a("Collection length: %d",n),n===0)return a("Finished processing a collection."),s(null,r);for(n0&&o();function o(){u-=1,a("Collection element %d: %s.",u,JSON.stringify(e[u])),t.length===3?t.call(i.thisArg,r,e[u],l):t.length===4?t.call(i.thisArg,r,e[u],u,l):t.call(i.thisArg,r,e[u],u,e,l);function l(w,A){if(!m){if(w)return m=!0,b(w);a("Accumulator: %s",JSON.stringify(A)),r=A,b()}}}function b(l){if(l)return a("Encountered an error: %s",l.message),s(l);if(f+=1,a("Processed %d of %d collection elements.",f,n),u>0)return o();if(f===n)return a("Finished processing a collection."),s(null,r)}}E.exports=L -});var q=c(function(X,F){ -var T=require('@stdlib/assert-is-function/dist'),S=require('@stdlib/assert-is-collection/dist'),y=require('@stdlib/error-tools-fmtprodmsg/dist'),B=require('@stdlib/constants-float64-pinf/dist'),z=x(),D=P();function G(e,r){var i,t,s;if(i={},arguments.length>1){if(t=z(i,e),t)throw t;s=r}else s=e;if(!T(s))throw new TypeError(y('1RZ3q',s));return i.series===void 0&&i.limit===void 0&&(i.series=!0),i.series?i.limit=1:i.limit||(i.limit=B),f;function f(m,v,n){if(!S(m))throw new TypeError(y('1RZAh',m));if(!T(n))throw new TypeError(y('1RZ3q',n));return D(m,v,i,s,u);function u(g,o){if(g)return n(g);n(null,o)}}}F.exports=G -});var N=c(function(Y,C){ -var p=q();function H(e,r,i,t,s){if(arguments.length<5)return p(i)(e,r,t);p(i,t)(e,r,s)}C.exports=H -});var K=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),V=N(),M=q();K(V,"factory",M);module.exports=V; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index acb9d67..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/limit.js", "../lib/factory.js", "../lib/main.js", "../lib/index.js"], - "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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\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 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 to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\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 === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, 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 ( !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, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\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* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nmodule.exports = reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' );\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, 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"], - "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,0BAA2B,EAkB/C,SAASE,EAAOC,EAAYC,EAAKC,EAAMC,EAAKC,EAAO,CAClD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMR,EAAW,OACjBF,EAAO,wBAAyBU,CAAI,EAE/BA,IAAQ,EACZ,OAAAV,EAAO,mCAAoC,EACpCM,EAAM,KAAMH,CAAI,EAYxB,IAVKO,EAAMN,EAAK,MACfK,EAAMC,EAEND,EAAML,EAAK,MAEZJ,EAAO,wBAAyBS,CAAI,EACpCT,EAAO,0BAA2BK,EAAI,MAAO,EAE7CE,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVE,EAAK,EAQP,SAASA,GAAO,CACfF,GAAO,EACPX,EAAO,6BAA8BW,EAAK,KAAK,UAAWT,EAAYS,CAAI,CAAE,CAAE,EACzEN,EAAI,SAAW,EACnBA,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGG,CAAG,EACxCT,EAAI,SAAW,EAC1BA,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGA,EAAKG,CAAG,EAExDT,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGA,EAAKT,EAAYY,CAAG,EAUrE,SAASA,EAAIC,EAAOC,EAAS,CAC5B,GAAK,CAAAR,EAIL,IAAKO,EACJ,OAAAP,EAAM,GACCS,EAAMF,CAAM,EAEpBf,EAAO,kBAAmB,KAAK,UAAWgB,CAAO,CAAE,EACnDb,EAAMa,EACNC,EAAK,EACN,CACD,CASA,SAASA,EAAMF,EAAQ,CACtB,GAAKA,EACJ,OAAAf,EAAO,2BAA4Be,EAAM,OAAQ,EAC1CT,EAAMS,CAAM,EAIpB,GAFAR,GAAS,EACTP,EAAO,0CAA2CO,EAAOG,CAAI,EACxDC,EAAM,EACV,OAAOE,EAAK,EAEb,GAAKN,IAAUG,EACd,OAAAV,EAAO,mCAAoC,EACpCM,EAAM,KAAMH,CAAI,CAEzB,CACD,CAKAL,EAAO,QAAUG,IC7IjB,IAAAiB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,gCAAiC,EACjDC,EAAW,IACXC,EAAQ,IAoEZ,SAASC,EAASC,EAASC,EAAM,CAChC,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,CAACP,EAAYW,CAAE,EACnB,MAAM,IAAI,UAAWT,EAAQ,mEAAoES,CAAE,CAAE,EAEtG,OAAKF,EAAK,SAAW,QAAUA,EAAK,QAAU,SAC7CA,EAAK,OAAS,IAEVA,EAAK,OACTA,EAAK,MAAQ,EACDA,EAAK,QACjBA,EAAK,MAAQN,GAEPS,EAaP,SAASA,EAAkBC,EAAYC,EAASC,EAAO,CACtD,GAAK,CAACd,EAAcY,CAAW,EAC9B,MAAM,IAAI,UAAWX,EAAQ,sEAAuEW,CAAW,CAAE,EAElH,GAAK,CAACb,EAAYe,CAAK,EACtB,MAAM,IAAI,UAAWb,EAAQ,mEAAoEa,CAAK,CAAE,EAEzG,OAAOV,EAAOQ,EAAYC,EAASL,EAAME,EAAGK,CAAK,EAUjD,SAASA,EAAMC,EAAOC,EAAM,CAC3B,GAAKD,EACJ,OAAOF,EAAME,CAAM,EAEpBF,EAAM,KAAMG,CAAI,CACjB,CACD,CACD,CAKAnB,EAAO,QAAUO,ICnKjB,IAAAa,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,IA8Dd,SAASC,EAAkBC,EAAYC,EAASC,EAASC,EAAKC,EAAO,CACpE,GAAK,UAAU,OAAS,EACvB,OAAON,EAASI,CAAQ,EAAGF,EAAYC,EAASE,CAAI,EAErDL,EAASI,EAASC,CAAI,EAAGH,EAAYC,EAASG,CAAK,CACpD,CAKAP,EAAO,QAAUE,IC9BjB,IAAIM,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "isPositiveInteger", "format", "validate", "opts", "options", "require_limit", "__commonJSMin", "exports", "module", "logger", "debug", "limit", "collection", "acc", "opts", "fcn", "done", "count", "flg", "lim", "len", "idx", "i", "next", "cb", "error", "result", "clbk", "require_factory", "__commonJSMin", "exports", "module", "isFunction", "isCollection", "format", "PINF", "validate", "limit", "factory", "options", "fcn", "opts", "err", "f", "reduceRightAsync", "collection", "initial", "done", "clbk", "error", "acc", "require_main", "__commonJSMin", "exports", "module", "factory", "reduceRightAsync", "collection", "initial", "options", "fcn", "done", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3f22669..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,224 +0,0 @@ - -{{alias}}( collection, initial, [options,] reducer, done ) - Applies a function against an accumulator and each element in a collection - and returns the accumulated result, iterating from right to left. - - When invoked, `reducer` is provided a maximum of five arguments: - - - `accumulator`: accumulated value - - `value`: collection value - - `index`: collection index - - `collection`: the input collection - - `next`: a callback to be invoked after processing a collection `value` - - The actual number of provided arguments depends on function length. If - `reducer` accepts three arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `next` - - If `reducer` accepts four arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `index` - - `next` - - For every other `reducer` signature, `reducer` is provided all five - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `accumulator`: accumulated value - - If a provided function calls the `next` callback with a truthy `error` - argument, the function suspends execution and immediately calls the `done` - callback for subsequent `error` handling. - - Execution is *not* guaranteed to be asynchronous. To guarantee asynchrony, - 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`). - - The function does not support dynamic collection resizing. - - If provided an empty collection, the function invokes the `done` callback - with the `initial` value as the second argument. - - The function does not skip `undefined` elements. - - When processing collection elements concurrently, *beware* of race - conditions when updating an accumulator. This is especially true when an - accumulator is a primitive (e.g., a number). In general, prefer object - accumulators. - - Parameters - ---------- - collection: Array|TypedArray|Object - Input collection over which to iterate. If provided an object, the - object must be array-like (excluding strings and functions). - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - reducer: Function - The function to invoke for each element in a collection. - - done: Function - A callback invoked either upon processing all collection elements or - upon encountering an error. - - Examples - -------- - // Basic usage: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, fcn, done ) - 3000 - 2500 - 1000 - 6500 - - // Limit number of concurrent invocations: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'limit': 2 }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 2500 - 3000 - 1000 - 6500 - - // Process concurrently: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'series': false }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 1000 - 2500 - 3000 - 6500 - - -{{alias}}.factory( [options,] fcn ) - Returns a function which applies a function against an accumulator and each - element in a collection and returns the accumulated result, iterating from - right to left. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - fcn: Function - The function to invoke for each element in a collection. - - Returns - ------- - out: Function - A function which invokes a function for each element in a collection. - - Examples - -------- - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > var opts = { 'series': false }; - > var f = {{alias}}.factory( opts, fcn ); - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > f( arr, acc, done ) - 1000 - 2500 - 3000 - 6500 - > acc = { 'sum': 0 }; - > arr = [ 1000, 1500, 2000 ]; - > f( arr, acc, done ) - 1000 - 1500 - 2000 - 4500 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index f0001b3..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,166 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unsafe-any */ - -import reduceRightAsync = require( './index' ); - -const reducer = ( acc: any, value: number, index: number, next: Function ) => { - acc.sum += value; - if ( index === void 0 ) { - throw new Error( '`index` is missing.' ); - } - next( null, acc ); -}; - -const done = ( error: Error | null, acc: any ) => { - if ( error ) { - throw error; - } - if ( acc === void 0 ) { - throw new Error( '`acc` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( 2, acc, reducer, done ); // $ExpectError - reduceRightAsync( false, acc, reducer, done ); // $ExpectError - reduceRightAsync( true, acc, reducer, done ); // $ExpectError - reduceRightAsync( {}, acc, reducer, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a predicate argument which is not a predicate function... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 2, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, false, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, true, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 'abc', done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, [], done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a done callback argument which is not a function having a supported signature... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 2 ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, false ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, true ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 'abc' ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, {} ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, [] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const acc = { 'sum': 0 }; - reduceRightAsync(); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, reducer, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - reduceRightAsync.factory( reducer ); // $ExpectType FactoryFunction - reduceRightAsync.factory( { 'series': true }, reducer ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - reduceRightAsync.factory( [], reducer ); // $ExpectError - reduceRightAsync.factory( 123, reducer ); // $ExpectError - reduceRightAsync.factory( 'abc', reducer ); // $ExpectError - reduceRightAsync.factory( false, reducer ); // $ExpectError - reduceRightAsync.factory( true, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not a predicate function... -{ - reduceRightAsync.factory( {} ); // $ExpectError - reduceRightAsync.factory( true ); // $ExpectError - reduceRightAsync.factory( false ); // $ExpectError - reduceRightAsync.factory( {}, 123 ); // $ExpectError - reduceRightAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1( 12, acc, done ); // $ExpectError - fcn1( true, acc, done ); // $ExpectError - fcn1( false, acc, done ); // $ExpectError - fcn1( {}, acc, done ); // $ExpectError - - fcn1( [ 3000, 2500, 1000 ], acc, 12 ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, true ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, false ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, '5' ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, {} ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, [] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1(); // $ExpectError - fcn1( [ 3000, 2500, 1000 ] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - reduceRightAsync.factory( { 'limit': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': true }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': false }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - reduceRightAsync.factory( { 'series': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': 12 }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - reduceRightAsync.factory(); // $ExpectError - reduceRightAsync.factory( {}, reducer, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index dd64345..0000000 --- a/examples/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var resolve = require( 'path' ).resolve; -var readFile = require( '@stdlib/fs-read-file' ); -var reduceRightAsync = require( './../lib' ); - -var files = [ - resolve( __dirname, '..', 'package.json' ), - resolve( __dirname, '..', 'README.md' ) -]; - -function done( error, acc ) { - if ( error ) { - throw error; - } - console.log( acc.count ); -} - -function read( acc, file, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( file, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( null, acc ); - } - acc.count += 1; - next( null, acc ); - } -} - -var acc = { - 'count': 0 -}; -reduceRightAsync( files, acc, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 80786cf..2657f80 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..7ebba12 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.0-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.0-esm/index.mjs";import{isPrimitive as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.1.0-esm/index.mjs";function m(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("1RZ2o,GE","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!d(e.limit))?new TypeError(r("1RZ3P,Fv","limit",e.limit)):null):new TypeError(r("1RZ2V,FD",t))}function c(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){if(this instanceof e){var i=[null];i.push.apply(i,arguments);var r=Function.bind.apply(t,i);return new r}return t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var f=c(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function p(e,t,i,r,s){var n,o,l,d,m,c;if(d=e.length,f("Collection length: %d",d),0===d)return f("Finished processing a collection."),s(null,t);for(l=d0&&p();function p(){function s(e,i){if(!o){if(e)return o=!0,u(e);f("Accumulator: %s",JSON.stringify(i)),t=i,u()}}f("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function u(e){return e?(f("Encountered an error: %s",e.message),s(e)):(f("Processed %d of %d collection elements.",n+=1,d),m>0?p():n===d?(f("Finished processing a collection."),s(null,t)):void 0)}}function u(e,n){var o,l,d;if(o={},arguments.length>1){if(l=m(o,e))throw l;d=n}else d=e;if(!t(d))throw new TypeError(r("1RZ3q,JV",d));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=s),c;function c(e,s,n){if(!i(e))throw new TypeError(r("1RZAh,O3",e));if(!t(n))throw new TypeError(r("1RZ3q,JV",n));return p(e,s,o,d,(function(e,t){if(e)return n(e);n(null,t)}))}}function a(e,t,i,r,s){if(arguments.length<5)return u(i)(e,t,r);u(i,r)(e,t,s)}e(a,"factory",u);export{a as default,u as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..655de94 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '1RZ2V,FD', 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( '1RZ2o,GE', '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( '1RZ3P,Fv', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RZ3q,JV', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '1RZAh,O3', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RZ3q,JV', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","logger","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly","main"],"mappings":";;w5BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,WAAY,SAAUR,EAAKK,SAGtDF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,WAAY,QAASR,EAAKS,QAGnD,MAjBC,IAAIF,UAAWC,EAAQ,WAAYP,GAkB5C,8eC/CIU,uDAAQC,CAAQ,4BAkBpB,SAASH,EAAOI,EAAYC,EAAKd,EAAMe,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMP,EAAWU,OACjBZ,EAAO,wBAAyBS,GAEnB,IAARA,EAEJ,OADAT,EAAO,qCACAK,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAEZE,EAAO,wBAAyBQ,GAChCR,EAAO,0BAA2BI,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdf,EAAO,kBAAmBkB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,GAPC,CAQD,CA5BDjB,EAAO,6BADPU,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJf,EAAO,2BAA4Be,EAAMM,SAClChB,EAAMU,KAGdf,EAAO,0CADPM,GAAS,EACgDG,GACpDC,EAAM,EACHG,IAEHP,IAAUG,GACdT,EAAO,qCACAK,EAAM,KAAMF,SAFpB,EAIA,CACF,CCzCA,SAASmB,EAAShC,EAASc,GAC1B,IAAIf,EACAkC,EACAC,EAGJ,GADAnC,EAAO,CAAA,EACFoC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMnC,EAAUC,EAAMC,GAErB,MAAMiC,EAEPC,EAAIpB,CACN,MACEoB,EAAIlC,EAEL,IAAMoC,EAAYF,GACjB,MAAM,IAAI5B,UAAWC,EAAQ,WAAY2B,IAU1C,YARqB,IAAhBnC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ6B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIN,UAAWC,EAAQ,WAAYK,IAE1C,IAAMwB,EAAYrB,GACjB,MAAM,IAAIT,UAAWC,EAAQ,WAAYQ,IAE1C,OAAOP,EAAOI,EAAY2B,EAASxC,EAAMmC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,EACZ,GACD,CACF,CC1EA,SAASyB,EAAkB1B,EAAY2B,EAASvC,EAASc,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAShC,EAATgC,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAShC,EAASc,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,EAC/C,CClBA0B,EAAAC,EAAA,UAAAV"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 1cd0d47..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,164 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var validate = require( './validate.js' ); -var limit = require( './limit.js' ); - - -// MAIN // - -/** -* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} last argument must be a function -* @returns {Function} function which invokes the provided function once for each element in a collection -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error, data ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var opts = { -* 'series': false -* }; -* -* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: -* var reduceRightAsync = factory( opts, read ); -* -* // Create a collection over which to iterate: -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* // Define a callback which handles errors: -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* // Run `read` for each element in `files`: -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, done ); -*/ -function factory( options, fcn ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = fcn; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '1RZ3q,JV', f ) ); - } - if ( opts.series === void 0 && opts.limit === void 0 ) { - opts.series = true; - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return reduceRightAsync; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * @private - * @param {Collection} collection - input collection - * @param {*} initial - initial value - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be a collection - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function reduceRightAsync( collection, initial, done ) { - if ( !isCollection( collection ) ) { - throw new TypeError( format( '1RZAh,O3', collection ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '1RZ3q,JV', done ) ); - } - return limit( collection, initial, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {*} [acc] - accumulated value - * @returns {void} - */ - function clbk( error, acc ) { - if ( error ) { - return done( error ); - } - done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ae657ff..0000000 --- a/lib/index.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* @module @stdlib/utils-async-reduce-right -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' ); -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/limit.js b/lib/limit.js deleted file mode 100644 index cdb60af..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); - - -// VARIABLES // - -var debug = logger( 'reduce-right-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each element in a collection, limiting the number of concurrently pending functions and iterating from right to left. -* -* @private -* @param {Collection} collection - input collection -* @param {*} acc - initial value -* @param {Options} opts - function options -* @param {*} [opts.thisArg] - execution context -* @param {PositiveInteger} [opts.limit] - maximum number of pending function invocations -* @param {Function} fcn - function to invoke -* @param {Callback} done - function to invoke upon completion or upon encountering an error -* @returns {void} -*/ -function limit( collection, acc, opts, fcn, done ) { - var count; - var flg; - var lim; - var len; - var idx; - var i; - - len = collection.length; - debug( 'Collection length: %d', len ); - - if ( len === 0 ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - count = 0; - idx = len; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all collection elements... - if ( idx > 0 ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next element in a collection. - * - * @private - */ - function next() { - idx -= 1; - debug( 'Collection element %d: %s.', idx, JSON.stringify( collection[ idx ] ) ); - if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], cb ); - } else if ( fcn.length === 4 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, cb ); - } else { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len - } - /** - * Callback invoked once a provided function finishes processing a collection element. - * - * @private - * @param {*} [error] - error - * @param {*} [result] - accumulation result - * @returns {void} - */ - function cb( error, result ) { - if ( flg ) { - // Prevent further processing of collection elements: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Accumulator: %s', JSON.stringify( result ) ); - acc = result; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next collection element. - * - * @private - * @param {*} [error] - error - * @returns {void} - */ - function clbk( error ) { - if ( error ) { - debug( 'Encountered an error: %s', error.message ); - return done( error ); - } - count += 1; - debug( 'Processed %d of %d collection elements.', count, len ); - if ( idx > 0 ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index c8b0d0f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param {Collection} collection - input collection -* @param {*} initial - initial value -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} second-to-last argument must be a function -* @throws {TypeError} last argument must be a function -* @returns {void} -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -function reduceRightAsync( collection, initial, options, fcn, done ) { - if ( arguments.length < 5 ) { - return factory( options )( collection, initial, fcn ); - } - factory( options, fcn )( collection, initial, done ); -} - - -// EXPORTS // - -module.exports = reduceRightAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index c90c17f..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @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 -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'thisArg': {}, -* 'series': false, -* 'limit': 10 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '1RZ2V,FD', options ) ); - } - if ( hasOwnProp( options, 'thisArg' ) ) { - opts.thisArg = options.thisArg; - } - if ( hasOwnProp( options, 'series' ) ) { - opts.series = options.series; - if ( !isBoolean( opts.series ) ) { - return new TypeError( format( '1RZ2o,GE', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '1RZ3P,Fv', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 9d271e6..d4f9525 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,43 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.1.0", - "@stdlib/assert-is-boolean": "^0.1.0", - "@stdlib/assert-is-collection": "^0.1.0", - "@stdlib/assert-is-function": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.0", - "@stdlib/assert-is-positive-integer": "^0.1.0", - "@stdlib/constants-float64-pinf": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.0", - "@stdlib/types": "^0.1.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.0", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/bench": "^0.1.0", - "@stdlib/constants-float64-eps": "^0.1.0", - "@stdlib/fs-read-file": "^0.1.0", - "@stdlib/utils-noop": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..7e91d61 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index 1d9403a..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var reduceRightAsync = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof reduceRightAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 8244931..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1095 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( {}, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, next ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - factory( opts, next ); - }; - } -}); - -tape( 'the function returns a function (no options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided a collection (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a collection (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (1 argument)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (2 arguments)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with five arguments', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn() { - var value; - var next; - var acc; - var k; - - acc = arguments[ 0 ]; - value = arguments[ 1 ]; - k = arguments[ 2 ]; - next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( k, i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the returned function supports processing collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements concurrently', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 100, 250, 300 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements sequentially (limit = 1)', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of collection elements which are processed at any one time', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 250, 300, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 250, 100, 300 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var reduceRightAsync; - var arr; - - reduceRightAsync = factory( fcn ); - arr = []; - - reduceRightAsync( arr, 0, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var reduceRightAsync; - var obj; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = []; - obj = {}; - reduceRightAsync( arr, obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - i = 0; - - reduceRightAsync( arr, {}, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, acc ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the returned function does not skip empty elements', function test( t ) { - var reduceRightAsync; - var expected; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index f273a40..0000000 --- a/test/test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof reduceRightAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 1893240..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1035 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a collection', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (no options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, next, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, 0 ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - reduceRightAsync( [ 1, 2, 3 ], 0, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (1 argument)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (2 arguments)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with five arguments', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn() { - var next; - var acc; - var v; - - next = arguments[ 4 ]; - acc = arguments[ 0 ]; - v = arguments[ 1 ]; - - i -= 1; - j += 1; - - t.strictEqual( v, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, v ); - - function onTimeout() { - acc.sum += v; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'by default, the function processes collection elements sequentially', function test( t ) { - var values; - var count; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements concurrently', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 100, 250, 300 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': true - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially (limit = 1)', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var arr; - var ctx; - - arr = [ 3, 2, 1 ]; - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 3, 2, 1 ]; - opts = { - 'series': true - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 250, 100, 300 ]; - opts = { - 'limit': 2 - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var arr = []; - reduceRightAsync( arr, 0, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var arr = []; - var obj = {}; - - reduceRightAsync( arr, obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - arr = [ 3, 2, 1 ]; - i = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, value ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the function does not skip empty elements', function test( t ) { - var expected; - var arr; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, fcn, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 7660838..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,181 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `limit` option which is not a positive integer', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - -5, - 0, - 3.14, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'limit': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `series` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'series': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function accepts any value for the `thisArg` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'thisArg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err, null, 'returns null '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'thisArg': {}, - 'series': false, - 'limit': 10 - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From cd3deea33259d5d193e1982d7dbc21c6bd7558c3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 5 Oct 2023 11:17:53 +0000 Subject: [PATCH 073/147] Transform error messages --- lib/factory.js | 8 ++++---- lib/validate.js | 8 ++++---- package.json | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 1125052..1cd0d47 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -22,7 +22,7 @@ var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var PINF = require( '@stdlib/constants-float64-pinf' ); var validate = require( './validate.js' ); var limit = require( './limit.js' ); @@ -109,7 +109,7 @@ function factory( options, fcn ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '1RZ3q,JV', f ) ); } if ( opts.series === void 0 && opts.limit === void 0 ) { opts.series = true; @@ -134,10 +134,10 @@ function factory( options, fcn ) { */ function reduceRightAsync( collection, initial, done ) { if ( !isCollection( collection ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a collection. Value: `%s`.', collection ) ); + throw new TypeError( format( '1RZAh,O3', collection ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '1RZ3q,JV', done ) ); } return limit( collection, initial, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index 9ba927e..c90c17f 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,7 +54,7 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '1RZ2V,FD', options ) ); } if ( hasOwnProp( options, 'thisArg' ) ) { opts.thisArg = options.thisArg; @@ -62,13 +62,13 @@ function validate( opts, options ) { if ( hasOwnProp( options, 'series' ) ) { opts.series = options.series; if ( !isBoolean( opts.series ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'series', opts.series ) ); + return new TypeError( format( '1RZ2o,GE', 'series', opts.series ) ); } } if ( hasOwnProp( options, 'limit' ) ) { opts.limit = options.limit; if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'limit', opts.limit ) ); + return new TypeError( format( '1RZ3P,Fv', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index 1456ee8..eda8c17 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-plain-object": "^0.1.1", "@stdlib/assert-is-positive-integer": "^0.1.0", "@stdlib/constants-float64-pinf": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.1.0", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1", "debug": "^2.6.9" From 96afb0e68d1542aa9df747e3db7e4635138694f9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 6 Oct 2023 14:38:23 +0000 Subject: [PATCH 074/147] Remove files --- index.d.ts | 410 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6592 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 2657f80..0000000 --- a/index.d.ts +++ /dev/null @@ -1,410 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Execution context. - */ - thisArg?: ThisParameterType>; - - /** - * The maximum number of pending invocations at any one time. - */ - limit?: number; - - /** - * Boolean indicating whether to sequentially invoke the reducer function for each `collection` element. If `true`, the function sets `options.limit=1`. Default: true. - */ - series?: boolean; -} - -/** -* Callback function. -*/ -type Nullary = () => void; - -/** -* Callback function. -* -* @param error - encountered error or null -*/ -type Unary = ( error: Error | null ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Binary = ( error: Error | null, accumulator: U ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param next - a callback to be invoked after processing a collection `value` -*/ -type TernaryReducer = ( this: V, accumulator: U, value: T, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuaternaryReducer = ( this: V, accumulator: U, value: T, index: number, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuinaryReducer = ( this: V, accumulator: U, value: T, index: number, collection: Collection, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type Reducer = TernaryReducer | QuaternaryReducer | QuinaryReducer; - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result. -* -* @param collection - input collection -* @param initial - initial value -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( collection: Collection, initial: U, done: Callback ) => void; - -/** -* Interface for `reduceRightAsync`. -*/ -interface ReduceRightAsync { - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, {}, read, done ); - */ - ( collection: Collection, initial: U, options: Options, reducer: Reducer, done: Callback ): void; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, read, done ); - */ - ( collection: Collection, initial: U, reducer: Reducer, done: Callback ): void; // tslint:disable-line:no-unnecessary-generics - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @throws must provide valid options - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var opts = { - * 'series': false - * }; - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( opts, read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( options: Options, reducer: Reducer ): FactoryFunction; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param reducer - function to invoke for each element in a collection - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( reducer: Reducer ): FactoryFunction; // tslint:disable-line:no-unnecessary-generics -} - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param collection - input collection -* @param initial - initial value -* @param options - function options -* @param options.thisArg - execution context -* @param options.limit - maximum number of pending invocations at any one time -* @param 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 (default: true) -* @param reducer - function to invoke for each element in a collection -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( `@stdlib/fs/read-file` ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -declare var reduceRightAsync: ReduceRightAsync; - - -// EXPORTS // - -export = reduceRightAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 7ebba12..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.0-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.0-esm/index.mjs";import{isPrimitive as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.1.0-esm/index.mjs";function m(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("1RZ2o,GE","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!d(e.limit))?new TypeError(r("1RZ3P,Fv","limit",e.limit)):null):new TypeError(r("1RZ2V,FD",t))}function c(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){if(this instanceof e){var i=[null];i.push.apply(i,arguments);var r=Function.bind.apply(t,i);return new r}return t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var f=c(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function p(e,t,i,r,s){var n,o,l,d,m,c;if(d=e.length,f("Collection length: %d",d),0===d)return f("Finished processing a collection."),s(null,t);for(l=d0&&p();function p(){function s(e,i){if(!o){if(e)return o=!0,u(e);f("Accumulator: %s",JSON.stringify(i)),t=i,u()}}f("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function u(e){return e?(f("Encountered an error: %s",e.message),s(e)):(f("Processed %d of %d collection elements.",n+=1,d),m>0?p():n===d?(f("Finished processing a collection."),s(null,t)):void 0)}}function u(e,n){var o,l,d;if(o={},arguments.length>1){if(l=m(o,e))throw l;d=n}else d=e;if(!t(d))throw new TypeError(r("1RZ3q,JV",d));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=s),c;function c(e,s,n){if(!i(e))throw new TypeError(r("1RZAh,O3",e));if(!t(n))throw new TypeError(r("1RZ3q,JV",n));return p(e,s,o,d,(function(e,t){if(e)return n(e);n(null,t)}))}}function a(e,t,i,r,s){if(arguments.length<5)return u(i)(e,t,r);u(i,r)(e,t,s)}e(a,"factory",u);export{a as default,u as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 655de94..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '1RZ2V,FD', 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( '1RZ2o,GE', '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( '1RZ3P,Fv', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RZ3q,JV', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '1RZAh,O3', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RZ3q,JV', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","logger","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly","main"],"mappings":";;w5BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,WAAY,SAAUR,EAAKK,SAGtDF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,WAAY,QAASR,EAAKS,QAGnD,MAjBC,IAAIF,UAAWC,EAAQ,WAAYP,GAkB5C,8eC/CIU,uDAAQC,CAAQ,4BAkBpB,SAASH,EAAOI,EAAYC,EAAKd,EAAMe,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMP,EAAWU,OACjBZ,EAAO,wBAAyBS,GAEnB,IAARA,EAEJ,OADAT,EAAO,qCACAK,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAEZE,EAAO,wBAAyBQ,GAChCR,EAAO,0BAA2BI,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdf,EAAO,kBAAmBkB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,GAPC,CAQD,CA5BDjB,EAAO,6BADPU,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJf,EAAO,2BAA4Be,EAAMM,SAClChB,EAAMU,KAGdf,EAAO,0CADPM,GAAS,EACgDG,GACpDC,EAAM,EACHG,IAEHP,IAAUG,GACdT,EAAO,qCACAK,EAAM,KAAMF,SAFpB,EAIA,CACF,CCzCA,SAASmB,EAAShC,EAASc,GAC1B,IAAIf,EACAkC,EACAC,EAGJ,GADAnC,EAAO,CAAA,EACFoC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMnC,EAAUC,EAAMC,GAErB,MAAMiC,EAEPC,EAAIpB,CACN,MACEoB,EAAIlC,EAEL,IAAMoC,EAAYF,GACjB,MAAM,IAAI5B,UAAWC,EAAQ,WAAY2B,IAU1C,YARqB,IAAhBnC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ6B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIN,UAAWC,EAAQ,WAAYK,IAE1C,IAAMwB,EAAYrB,GACjB,MAAM,IAAIT,UAAWC,EAAQ,WAAYQ,IAE1C,OAAOP,EAAOI,EAAY2B,EAASxC,EAAMmC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,EACZ,GACD,CACF,CC1EA,SAASyB,EAAkB1B,EAAY2B,EAASvC,EAASc,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAShC,EAATgC,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAShC,EAASc,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,EAC/C,CClBA0B,EAAAC,EAAA,UAAAV"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 7e91d61..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From ad3dfc5ee9b42b914e29aee61c99970ae60a477e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 6 Oct 2023 14:39:08 +0000 Subject: [PATCH 075/147] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 247 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 47 +- benchmark/benchmark.factory.js | 73 - benchmark/benchmark.js | 160 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 224 - docs/types/test.ts | 166 - examples/index.js | 55 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 164 - lib/index.js | 77 - lib/limit.js | 142 - lib/main.js | 95 - lib/validate.js | 80 - package.json | 64 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 38 - test/test.factory.js | 1095 ---- test/test.js | 38 - test/test.main.js | 1035 ---- test/test.validate.js | 181 - 48 files changed, 6208 insertions(+), 6943 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/limit.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1e08946..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 5358060..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 372758f..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '37 1 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -458,7 +457,7 @@ reduceRightAsync( files, acc, read, done ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -526,11 +525,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right +[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right/tree/esm -[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce +[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/tree/esm diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 46d8b83..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var reduceRightAsync; - var arr; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - reduceRightAsync = factory( onItem ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - var acc; - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 6ad0714..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var reduceRightAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=false', function benchmark( b ) { - var opts; - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'series': false - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var arr; - var len; - var acc; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'limit': 3 - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index acfc6d6..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right" -%% click B href "https://github.com/stdlib-js/utils-async-reduce-right/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-reduce-right/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-reduce-right/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-reduce-right/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right -[production-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 47a072e..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import reduceRightAsync from '../docs/types/index'; -export = reduceRightAsync; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 530ca4d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var c=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var x=c(function(U,O){ -var R=require('@stdlib/assert-is-plain-object/dist'),h=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,k=require('@stdlib/assert-is-positive-integer/dist').isPrimitive,d=require('@stdlib/error-tools-fmtprodmsg/dist');function I(e,r){return R(r)?(h(r,"thisArg")&&(e.thisArg=r.thisArg),h(r,"series")&&(e.series=r.series,!j(e.series))?new TypeError(d('1RZ2o',"series",e.series)):h(r,"limit")&&(e.limit=r.limit,!k(e.limit))?new TypeError(d('1RZ3P',"limit",e.limit)):null):new TypeError(d('1RZ2V',r));}O.exports=I -});var P=c(function(W,E){ -var J=require("debug"),a=J("reduce-right-async:limit");function L(e,r,i,t,s){var f,m,v,n,u,g;if(n=e.length,a("Collection length: %d",n),n===0)return a("Finished processing a collection."),s(null,r);for(n0&&o();function o(){u-=1,a("Collection element %d: %s.",u,JSON.stringify(e[u])),t.length===3?t.call(i.thisArg,r,e[u],l):t.length===4?t.call(i.thisArg,r,e[u],u,l):t.call(i.thisArg,r,e[u],u,e,l);function l(w,A){if(!m){if(w)return m=!0,b(w);a("Accumulator: %s",JSON.stringify(A)),r=A,b()}}}function b(l){if(l)return a("Encountered an error: %s",l.message),s(l);if(f+=1,a("Processed %d of %d collection elements.",f,n),u>0)return o();if(f===n)return a("Finished processing a collection."),s(null,r)}}E.exports=L -});var q=c(function(X,F){ -var T=require('@stdlib/assert-is-function/dist'),S=require('@stdlib/assert-is-collection/dist'),y=require('@stdlib/error-tools-fmtprodmsg/dist'),B=require('@stdlib/constants-float64-pinf/dist'),z=x(),D=P();function G(e,r){var i,t,s;if(i={},arguments.length>1){if(t=z(i,e),t)throw t;s=r}else s=e;if(!T(s))throw new TypeError(y('1RZ3q',s));return i.series===void 0&&i.limit===void 0&&(i.series=!0),i.series?i.limit=1:i.limit||(i.limit=B),f;function f(m,v,n){if(!S(m))throw new TypeError(y('1RZAh',m));if(!T(n))throw new TypeError(y('1RZ3q',n));return D(m,v,i,s,u);function u(g,o){if(g)return n(g);n(null,o)}}}F.exports=G -});var N=c(function(Y,C){ -var p=q();function H(e,r,i,t,s){if(arguments.length<5)return p(i)(e,r,t);p(i,t)(e,r,s)}C.exports=H -});var K=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),V=N(),M=q();K(V,"factory",M);module.exports=V; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index acb9d67..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/limit.js", "../lib/factory.js", "../lib/main.js", "../lib/index.js"], - "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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\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 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 to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\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 === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, 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 ( !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, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\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* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nmodule.exports = reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' );\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, 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"], - "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,0BAA2B,EAkB/C,SAASE,EAAOC,EAAYC,EAAKC,EAAMC,EAAKC,EAAO,CAClD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMR,EAAW,OACjBF,EAAO,wBAAyBU,CAAI,EAE/BA,IAAQ,EACZ,OAAAV,EAAO,mCAAoC,EACpCM,EAAM,KAAMH,CAAI,EAYxB,IAVKO,EAAMN,EAAK,MACfK,EAAMC,EAEND,EAAML,EAAK,MAEZJ,EAAO,wBAAyBS,CAAI,EACpCT,EAAO,0BAA2BK,EAAI,MAAO,EAE7CE,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVE,EAAK,EAQP,SAASA,GAAO,CACfF,GAAO,EACPX,EAAO,6BAA8BW,EAAK,KAAK,UAAWT,EAAYS,CAAI,CAAE,CAAE,EACzEN,EAAI,SAAW,EACnBA,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGG,CAAG,EACxCT,EAAI,SAAW,EAC1BA,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGA,EAAKG,CAAG,EAExDT,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGA,EAAKT,EAAYY,CAAG,EAUrE,SAASA,EAAIC,EAAOC,EAAS,CAC5B,GAAK,CAAAR,EAIL,IAAKO,EACJ,OAAAP,EAAM,GACCS,EAAMF,CAAM,EAEpBf,EAAO,kBAAmB,KAAK,UAAWgB,CAAO,CAAE,EACnDb,EAAMa,EACNC,EAAK,EACN,CACD,CASA,SAASA,EAAMF,EAAQ,CACtB,GAAKA,EACJ,OAAAf,EAAO,2BAA4Be,EAAM,OAAQ,EAC1CT,EAAMS,CAAM,EAIpB,GAFAR,GAAS,EACTP,EAAO,0CAA2CO,EAAOG,CAAI,EACxDC,EAAM,EACV,OAAOE,EAAK,EAEb,GAAKN,IAAUG,EACd,OAAAV,EAAO,mCAAoC,EACpCM,EAAM,KAAMH,CAAI,CAEzB,CACD,CAKAL,EAAO,QAAUG,IC7IjB,IAAAiB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,gCAAiC,EACjDC,EAAW,IACXC,EAAQ,IAoEZ,SAASC,EAASC,EAASC,EAAM,CAChC,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,CAACP,EAAYW,CAAE,EACnB,MAAM,IAAI,UAAWT,EAAQ,mEAAoES,CAAE,CAAE,EAEtG,OAAKF,EAAK,SAAW,QAAUA,EAAK,QAAU,SAC7CA,EAAK,OAAS,IAEVA,EAAK,OACTA,EAAK,MAAQ,EACDA,EAAK,QACjBA,EAAK,MAAQN,GAEPS,EAaP,SAASA,EAAkBC,EAAYC,EAASC,EAAO,CACtD,GAAK,CAACd,EAAcY,CAAW,EAC9B,MAAM,IAAI,UAAWX,EAAQ,sEAAuEW,CAAW,CAAE,EAElH,GAAK,CAACb,EAAYe,CAAK,EACtB,MAAM,IAAI,UAAWb,EAAQ,mEAAoEa,CAAK,CAAE,EAEzG,OAAOV,EAAOQ,EAAYC,EAASL,EAAME,EAAGK,CAAK,EAUjD,SAASA,EAAMC,EAAOC,EAAM,CAC3B,GAAKD,EACJ,OAAOF,EAAME,CAAM,EAEpBF,EAAM,KAAMG,CAAI,CACjB,CACD,CACD,CAKAnB,EAAO,QAAUO,ICnKjB,IAAAa,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,IA8Dd,SAASC,EAAkBC,EAAYC,EAASC,EAASC,EAAKC,EAAO,CACpE,GAAK,UAAU,OAAS,EACvB,OAAON,EAASI,CAAQ,EAAGF,EAAYC,EAASE,CAAI,EAErDL,EAASI,EAASC,CAAI,EAAGH,EAAYC,EAASG,CAAK,CACpD,CAKAP,EAAO,QAAUE,IC9BjB,IAAIM,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "isPositiveInteger", "format", "validate", "opts", "options", "require_limit", "__commonJSMin", "exports", "module", "logger", "debug", "limit", "collection", "acc", "opts", "fcn", "done", "count", "flg", "lim", "len", "idx", "i", "next", "cb", "error", "result", "clbk", "require_factory", "__commonJSMin", "exports", "module", "isFunction", "isCollection", "format", "PINF", "validate", "limit", "factory", "options", "fcn", "opts", "err", "f", "reduceRightAsync", "collection", "initial", "done", "clbk", "error", "acc", "require_main", "__commonJSMin", "exports", "module", "factory", "reduceRightAsync", "collection", "initial", "options", "fcn", "done", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3f22669..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,224 +0,0 @@ - -{{alias}}( collection, initial, [options,] reducer, done ) - Applies a function against an accumulator and each element in a collection - and returns the accumulated result, iterating from right to left. - - When invoked, `reducer` is provided a maximum of five arguments: - - - `accumulator`: accumulated value - - `value`: collection value - - `index`: collection index - - `collection`: the input collection - - `next`: a callback to be invoked after processing a collection `value` - - The actual number of provided arguments depends on function length. If - `reducer` accepts three arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `next` - - If `reducer` accepts four arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `index` - - `next` - - For every other `reducer` signature, `reducer` is provided all five - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `accumulator`: accumulated value - - If a provided function calls the `next` callback with a truthy `error` - argument, the function suspends execution and immediately calls the `done` - callback for subsequent `error` handling. - - Execution is *not* guaranteed to be asynchronous. To guarantee asynchrony, - 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`). - - The function does not support dynamic collection resizing. - - If provided an empty collection, the function invokes the `done` callback - with the `initial` value as the second argument. - - The function does not skip `undefined` elements. - - When processing collection elements concurrently, *beware* of race - conditions when updating an accumulator. This is especially true when an - accumulator is a primitive (e.g., a number). In general, prefer object - accumulators. - - Parameters - ---------- - collection: Array|TypedArray|Object - Input collection over which to iterate. If provided an object, the - object must be array-like (excluding strings and functions). - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - reducer: Function - The function to invoke for each element in a collection. - - done: Function - A callback invoked either upon processing all collection elements or - upon encountering an error. - - Examples - -------- - // Basic usage: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, fcn, done ) - 3000 - 2500 - 1000 - 6500 - - // Limit number of concurrent invocations: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'limit': 2 }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 2500 - 3000 - 1000 - 6500 - - // Process concurrently: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'series': false }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 1000 - 2500 - 3000 - 6500 - - -{{alias}}.factory( [options,] fcn ) - Returns a function which applies a function against an accumulator and each - element in a collection and returns the accumulated result, iterating from - right to left. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - fcn: Function - The function to invoke for each element in a collection. - - Returns - ------- - out: Function - A function which invokes a function for each element in a collection. - - Examples - -------- - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > var opts = { 'series': false }; - > var f = {{alias}}.factory( opts, fcn ); - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > f( arr, acc, done ) - 1000 - 2500 - 3000 - 6500 - > acc = { 'sum': 0 }; - > arr = [ 1000, 1500, 2000 ]; - > f( arr, acc, done ) - 1000 - 1500 - 2000 - 4500 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index f0001b3..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,166 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unsafe-any */ - -import reduceRightAsync = require( './index' ); - -const reducer = ( acc: any, value: number, index: number, next: Function ) => { - acc.sum += value; - if ( index === void 0 ) { - throw new Error( '`index` is missing.' ); - } - next( null, acc ); -}; - -const done = ( error: Error | null, acc: any ) => { - if ( error ) { - throw error; - } - if ( acc === void 0 ) { - throw new Error( '`acc` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( 2, acc, reducer, done ); // $ExpectError - reduceRightAsync( false, acc, reducer, done ); // $ExpectError - reduceRightAsync( true, acc, reducer, done ); // $ExpectError - reduceRightAsync( {}, acc, reducer, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a predicate argument which is not a predicate function... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 2, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, false, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, true, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 'abc', done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, [], done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a done callback argument which is not a function having a supported signature... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 2 ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, false ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, true ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 'abc' ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, {} ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, [] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const acc = { 'sum': 0 }; - reduceRightAsync(); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, reducer, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - reduceRightAsync.factory( reducer ); // $ExpectType FactoryFunction - reduceRightAsync.factory( { 'series': true }, reducer ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - reduceRightAsync.factory( [], reducer ); // $ExpectError - reduceRightAsync.factory( 123, reducer ); // $ExpectError - reduceRightAsync.factory( 'abc', reducer ); // $ExpectError - reduceRightAsync.factory( false, reducer ); // $ExpectError - reduceRightAsync.factory( true, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not a predicate function... -{ - reduceRightAsync.factory( {} ); // $ExpectError - reduceRightAsync.factory( true ); // $ExpectError - reduceRightAsync.factory( false ); // $ExpectError - reduceRightAsync.factory( {}, 123 ); // $ExpectError - reduceRightAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1( 12, acc, done ); // $ExpectError - fcn1( true, acc, done ); // $ExpectError - fcn1( false, acc, done ); // $ExpectError - fcn1( {}, acc, done ); // $ExpectError - - fcn1( [ 3000, 2500, 1000 ], acc, 12 ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, true ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, false ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, '5' ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, {} ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, [] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1(); // $ExpectError - fcn1( [ 3000, 2500, 1000 ] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - reduceRightAsync.factory( { 'limit': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': true }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': false }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - reduceRightAsync.factory( { 'series': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': 12 }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - reduceRightAsync.factory(); // $ExpectError - reduceRightAsync.factory( {}, reducer, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index dd64345..0000000 --- a/examples/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var resolve = require( 'path' ).resolve; -var readFile = require( '@stdlib/fs-read-file' ); -var reduceRightAsync = require( './../lib' ); - -var files = [ - resolve( __dirname, '..', 'package.json' ), - resolve( __dirname, '..', 'README.md' ) -]; - -function done( error, acc ) { - if ( error ) { - throw error; - } - console.log( acc.count ); -} - -function read( acc, file, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( file, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( null, acc ); - } - acc.count += 1; - next( null, acc ); - } -} - -var acc = { - 'count': 0 -}; -reduceRightAsync( files, acc, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 80786cf..2657f80 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..2c6cb00 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import{isPrimitive as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.1.0-esm/index.mjs";function m(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("1RZ2o,GE","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!d(e.limit))?new TypeError(r("1RZ3P,Fv","limit",e.limit)):null):new TypeError(r("1RZ2V,FD",t))}function c(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){if(this instanceof e){var i=[null];i.push.apply(i,arguments);var r=Function.bind.apply(t,i);return new r}return t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var f=c(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function p(e,t,i,r,s){var n,o,l,d,m,c;if(d=e.length,f("Collection length: %d",d),0===d)return f("Finished processing a collection."),s(null,t);for(l=d0&&p();function p(){function s(e,i){if(!o){if(e)return o=!0,u(e);f("Accumulator: %s",JSON.stringify(i)),t=i,u()}}f("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function u(e){return e?(f("Encountered an error: %s",e.message),s(e)):(f("Processed %d of %d collection elements.",n+=1,d),m>0?p():n===d?(f("Finished processing a collection."),s(null,t)):void 0)}}function u(e,n){var o,l,d;if(o={},arguments.length>1){if(l=m(o,e))throw l;d=n}else d=e;if(!t(d))throw new TypeError(r("1RZ3q,JV",d));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=s),c;function c(e,s,n){if(!i(e))throw new TypeError(r("1RZAh,O3",e));if(!t(n))throw new TypeError(r("1RZ3q,JV",n));return p(e,s,o,d,(function(e,t){if(e)return n(e);n(null,t)}))}}function a(e,t,i,r,s){if(arguments.length<5)return u(i)(e,t,r);u(i,r)(e,t,s)}e(a,"factory",u);export{a as default,u as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..655de94 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '1RZ2V,FD', 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( '1RZ2o,GE', '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( '1RZ3P,Fv', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RZ3q,JV', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '1RZAh,O3', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RZ3q,JV', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","logger","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly","main"],"mappings":";;w5BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,WAAY,SAAUR,EAAKK,SAGtDF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,WAAY,QAASR,EAAKS,QAGnD,MAjBC,IAAIF,UAAWC,EAAQ,WAAYP,GAkB5C,8eC/CIU,uDAAQC,CAAQ,4BAkBpB,SAASH,EAAOI,EAAYC,EAAKd,EAAMe,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMP,EAAWU,OACjBZ,EAAO,wBAAyBS,GAEnB,IAARA,EAEJ,OADAT,EAAO,qCACAK,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAEZE,EAAO,wBAAyBQ,GAChCR,EAAO,0BAA2BI,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdf,EAAO,kBAAmBkB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,GAPC,CAQD,CA5BDjB,EAAO,6BADPU,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJf,EAAO,2BAA4Be,EAAMM,SAClChB,EAAMU,KAGdf,EAAO,0CADPM,GAAS,EACgDG,GACpDC,EAAM,EACHG,IAEHP,IAAUG,GACdT,EAAO,qCACAK,EAAM,KAAMF,SAFpB,EAIA,CACF,CCzCA,SAASmB,EAAShC,EAASc,GAC1B,IAAIf,EACAkC,EACAC,EAGJ,GADAnC,EAAO,CAAA,EACFoC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMnC,EAAUC,EAAMC,GAErB,MAAMiC,EAEPC,EAAIpB,CACN,MACEoB,EAAIlC,EAEL,IAAMoC,EAAYF,GACjB,MAAM,IAAI5B,UAAWC,EAAQ,WAAY2B,IAU1C,YARqB,IAAhBnC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ6B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIN,UAAWC,EAAQ,WAAYK,IAE1C,IAAMwB,EAAYrB,GACjB,MAAM,IAAIT,UAAWC,EAAQ,WAAYQ,IAE1C,OAAOP,EAAOI,EAAY2B,EAASxC,EAAMmC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,EACZ,GACD,CACF,CC1EA,SAASyB,EAAkB1B,EAAY2B,EAASvC,EAASc,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAShC,EAATgC,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAShC,EAASc,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,EAC/C,CClBA0B,EAAAC,EAAA,UAAAV"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 1cd0d47..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,164 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var validate = require( './validate.js' ); -var limit = require( './limit.js' ); - - -// MAIN // - -/** -* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} last argument must be a function -* @returns {Function} function which invokes the provided function once for each element in a collection -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error, data ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var opts = { -* 'series': false -* }; -* -* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: -* var reduceRightAsync = factory( opts, read ); -* -* // Create a collection over which to iterate: -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* // Define a callback which handles errors: -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* // Run `read` for each element in `files`: -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, done ); -*/ -function factory( options, fcn ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = fcn; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '1RZ3q,JV', f ) ); - } - if ( opts.series === void 0 && opts.limit === void 0 ) { - opts.series = true; - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return reduceRightAsync; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * @private - * @param {Collection} collection - input collection - * @param {*} initial - initial value - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be a collection - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function reduceRightAsync( collection, initial, done ) { - if ( !isCollection( collection ) ) { - throw new TypeError( format( '1RZAh,O3', collection ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '1RZ3q,JV', done ) ); - } - return limit( collection, initial, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {*} [acc] - accumulated value - * @returns {void} - */ - function clbk( error, acc ) { - if ( error ) { - return done( error ); - } - done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ae657ff..0000000 --- a/lib/index.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* @module @stdlib/utils-async-reduce-right -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' ); -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/limit.js b/lib/limit.js deleted file mode 100644 index cdb60af..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); - - -// VARIABLES // - -var debug = logger( 'reduce-right-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each element in a collection, limiting the number of concurrently pending functions and iterating from right to left. -* -* @private -* @param {Collection} collection - input collection -* @param {*} acc - initial value -* @param {Options} opts - function options -* @param {*} [opts.thisArg] - execution context -* @param {PositiveInteger} [opts.limit] - maximum number of pending function invocations -* @param {Function} fcn - function to invoke -* @param {Callback} done - function to invoke upon completion or upon encountering an error -* @returns {void} -*/ -function limit( collection, acc, opts, fcn, done ) { - var count; - var flg; - var lim; - var len; - var idx; - var i; - - len = collection.length; - debug( 'Collection length: %d', len ); - - if ( len === 0 ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - count = 0; - idx = len; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all collection elements... - if ( idx > 0 ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next element in a collection. - * - * @private - */ - function next() { - idx -= 1; - debug( 'Collection element %d: %s.', idx, JSON.stringify( collection[ idx ] ) ); - if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], cb ); - } else if ( fcn.length === 4 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, cb ); - } else { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len - } - /** - * Callback invoked once a provided function finishes processing a collection element. - * - * @private - * @param {*} [error] - error - * @param {*} [result] - accumulation result - * @returns {void} - */ - function cb( error, result ) { - if ( flg ) { - // Prevent further processing of collection elements: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Accumulator: %s', JSON.stringify( result ) ); - acc = result; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next collection element. - * - * @private - * @param {*} [error] - error - * @returns {void} - */ - function clbk( error ) { - if ( error ) { - debug( 'Encountered an error: %s', error.message ); - return done( error ); - } - count += 1; - debug( 'Processed %d of %d collection elements.', count, len ); - if ( idx > 0 ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index c8b0d0f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param {Collection} collection - input collection -* @param {*} initial - initial value -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} second-to-last argument must be a function -* @throws {TypeError} last argument must be a function -* @returns {void} -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -function reduceRightAsync( collection, initial, options, fcn, done ) { - if ( arguments.length < 5 ) { - return factory( options )( collection, initial, fcn ); - } - factory( options, fcn )( collection, initial, done ); -} - - -// EXPORTS // - -module.exports = reduceRightAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index c90c17f..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @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 -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'thisArg': {}, -* 'series': false, -* 'limit': 10 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '1RZ2V,FD', options ) ); - } - if ( hasOwnProp( options, 'thisArg' ) ) { - opts.thisArg = options.thisArg; - } - if ( hasOwnProp( options, 'series' ) ) { - opts.series = options.series; - if ( !isBoolean( opts.series ) ) { - return new TypeError( format( '1RZ2o,GE', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '1RZ3P,Fv', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index eda8c17..d4f9525 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,43 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-boolean": "^0.1.1", - "@stdlib/assert-is-collection": "^0.1.0", - "@stdlib/assert-is-function": "^0.1.1", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/assert-is-positive-integer": "^0.1.0", - "@stdlib/constants-float64-pinf": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.1.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/bench": "^0.1.0", - "@stdlib/constants-float64-eps": "^0.1.1", - "@stdlib/fs-read-file": "^0.1.1", - "@stdlib/utils-noop": "^0.1.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..5db7d42 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index 1d9403a..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var reduceRightAsync = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof reduceRightAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 8244931..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1095 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( {}, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, next ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - factory( opts, next ); - }; - } -}); - -tape( 'the function returns a function (no options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided a collection (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a collection (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (1 argument)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (2 arguments)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with five arguments', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn() { - var value; - var next; - var acc; - var k; - - acc = arguments[ 0 ]; - value = arguments[ 1 ]; - k = arguments[ 2 ]; - next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( k, i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the returned function supports processing collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements concurrently', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 100, 250, 300 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements sequentially (limit = 1)', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of collection elements which are processed at any one time', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 250, 300, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 250, 100, 300 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var reduceRightAsync; - var arr; - - reduceRightAsync = factory( fcn ); - arr = []; - - reduceRightAsync( arr, 0, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var reduceRightAsync; - var obj; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = []; - obj = {}; - reduceRightAsync( arr, obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - i = 0; - - reduceRightAsync( arr, {}, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, acc ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the returned function does not skip empty elements', function test( t ) { - var reduceRightAsync; - var expected; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index f273a40..0000000 --- a/test/test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof reduceRightAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 1893240..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1035 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a collection', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (no options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, next, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, 0 ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - reduceRightAsync( [ 1, 2, 3 ], 0, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (1 argument)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (2 arguments)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with five arguments', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn() { - var next; - var acc; - var v; - - next = arguments[ 4 ]; - acc = arguments[ 0 ]; - v = arguments[ 1 ]; - - i -= 1; - j += 1; - - t.strictEqual( v, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, v ); - - function onTimeout() { - acc.sum += v; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'by default, the function processes collection elements sequentially', function test( t ) { - var values; - var count; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements concurrently', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 100, 250, 300 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': true - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially (limit = 1)', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var arr; - var ctx; - - arr = [ 3, 2, 1 ]; - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 3, 2, 1 ]; - opts = { - 'series': true - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 250, 100, 300 ]; - opts = { - 'limit': 2 - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var arr = []; - reduceRightAsync( arr, 0, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var arr = []; - var obj = {}; - - reduceRightAsync( arr, obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - arr = [ 3, 2, 1 ]; - i = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, value ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the function does not skip empty elements', function test( t ) { - var expected; - var arr; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, fcn, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 7660838..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,181 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `limit` option which is not a positive integer', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - -5, - 0, - 3.14, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'limit': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `series` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'series': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function accepts any value for the `thisArg` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'thisArg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err, null, 'returns null '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'thisArg': {}, - 'series': false, - 'limit': 10 - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From c3b6a3882be70bd9fae5a151f1ad9b93c8793aba Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Nov 2023 08:07:20 +0000 Subject: [PATCH 076/147] Transform error messages --- lib/factory.js | 8 ++++---- lib/validate.js | 8 ++++---- package.json | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 1125052..1cd0d47 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -22,7 +22,7 @@ var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var PINF = require( '@stdlib/constants-float64-pinf' ); var validate = require( './validate.js' ); var limit = require( './limit.js' ); @@ -109,7 +109,7 @@ function factory( options, fcn ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '1RZ3q,JV', f ) ); } if ( opts.series === void 0 && opts.limit === void 0 ) { opts.series = true; @@ -134,10 +134,10 @@ function factory( options, fcn ) { */ function reduceRightAsync( collection, initial, done ) { if ( !isCollection( collection ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a collection. Value: `%s`.', collection ) ); + throw new TypeError( format( '1RZAh,O3', collection ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '1RZ3q,JV', done ) ); } return limit( collection, initial, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index 9ba927e..c90c17f 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,7 +54,7 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '1RZ2V,FD', options ) ); } if ( hasOwnProp( options, 'thisArg' ) ) { opts.thisArg = options.thisArg; @@ -62,13 +62,13 @@ function validate( opts, options ) { if ( hasOwnProp( options, 'series' ) ) { opts.series = options.series; if ( !isBoolean( opts.series ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'series', opts.series ) ); + return new TypeError( format( '1RZ2o,GE', 'series', opts.series ) ); } } if ( hasOwnProp( options, 'limit' ) ) { opts.limit = options.limit; if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'limit', opts.limit ) ); + return new TypeError( format( '1RZ3P,Fv', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index 1456ee8..eda8c17 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-plain-object": "^0.1.1", "@stdlib/assert-is-positive-integer": "^0.1.0", "@stdlib/constants-float64-pinf": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.1.0", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1", "debug": "^2.6.9" From 956733e374c630799f6a5622bbc2ea9cfb07678b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 2 Nov 2023 13:36:19 +0000 Subject: [PATCH 077/147] Remove files --- index.d.ts | 410 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6592 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 2657f80..0000000 --- a/index.d.ts +++ /dev/null @@ -1,410 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Execution context. - */ - thisArg?: ThisParameterType>; - - /** - * The maximum number of pending invocations at any one time. - */ - limit?: number; - - /** - * Boolean indicating whether to sequentially invoke the reducer function for each `collection` element. If `true`, the function sets `options.limit=1`. Default: true. - */ - series?: boolean; -} - -/** -* Callback function. -*/ -type Nullary = () => void; - -/** -* Callback function. -* -* @param error - encountered error or null -*/ -type Unary = ( error: Error | null ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Binary = ( error: Error | null, accumulator: U ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param next - a callback to be invoked after processing a collection `value` -*/ -type TernaryReducer = ( this: V, accumulator: U, value: T, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuaternaryReducer = ( this: V, accumulator: U, value: T, index: number, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuinaryReducer = ( this: V, accumulator: U, value: T, index: number, collection: Collection, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type Reducer = TernaryReducer | QuaternaryReducer | QuinaryReducer; - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result. -* -* @param collection - input collection -* @param initial - initial value -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( collection: Collection, initial: U, done: Callback ) => void; - -/** -* Interface for `reduceRightAsync`. -*/ -interface ReduceRightAsync { - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, {}, read, done ); - */ - ( collection: Collection, initial: U, options: Options, reducer: Reducer, done: Callback ): void; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, read, done ); - */ - ( collection: Collection, initial: U, reducer: Reducer, done: Callback ): void; // tslint:disable-line:no-unnecessary-generics - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @throws must provide valid options - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var opts = { - * 'series': false - * }; - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( opts, read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( options: Options, reducer: Reducer ): FactoryFunction; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param reducer - function to invoke for each element in a collection - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( reducer: Reducer ): FactoryFunction; // tslint:disable-line:no-unnecessary-generics -} - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param collection - input collection -* @param initial - initial value -* @param options - function options -* @param options.thisArg - execution context -* @param options.limit - maximum number of pending invocations at any one time -* @param 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 (default: true) -* @param reducer - function to invoke for each element in a collection -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( `@stdlib/fs/read-file` ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -declare var reduceRightAsync: ReduceRightAsync; - - -// EXPORTS // - -export = reduceRightAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 2c6cb00..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import{isPrimitive as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.1.0-esm/index.mjs";function m(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("1RZ2o,GE","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!d(e.limit))?new TypeError(r("1RZ3P,Fv","limit",e.limit)):null):new TypeError(r("1RZ2V,FD",t))}function c(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){if(this instanceof e){var i=[null];i.push.apply(i,arguments);var r=Function.bind.apply(t,i);return new r}return t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var f=c(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function p(e,t,i,r,s){var n,o,l,d,m,c;if(d=e.length,f("Collection length: %d",d),0===d)return f("Finished processing a collection."),s(null,t);for(l=d0&&p();function p(){function s(e,i){if(!o){if(e)return o=!0,u(e);f("Accumulator: %s",JSON.stringify(i)),t=i,u()}}f("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function u(e){return e?(f("Encountered an error: %s",e.message),s(e)):(f("Processed %d of %d collection elements.",n+=1,d),m>0?p():n===d?(f("Finished processing a collection."),s(null,t)):void 0)}}function u(e,n){var o,l,d;if(o={},arguments.length>1){if(l=m(o,e))throw l;d=n}else d=e;if(!t(d))throw new TypeError(r("1RZ3q,JV",d));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=s),c;function c(e,s,n){if(!i(e))throw new TypeError(r("1RZAh,O3",e));if(!t(n))throw new TypeError(r("1RZ3q,JV",n));return p(e,s,o,d,(function(e,t){if(e)return n(e);n(null,t)}))}}function a(e,t,i,r,s){if(arguments.length<5)return u(i)(e,t,r);u(i,r)(e,t,s)}e(a,"factory",u);export{a as default,u as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 655de94..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '1RZ2V,FD', 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( '1RZ2o,GE', '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( '1RZ3P,Fv', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RZ3q,JV', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '1RZAh,O3', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RZ3q,JV', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","logger","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly","main"],"mappings":";;w5BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,WAAY,SAAUR,EAAKK,SAGtDF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,WAAY,QAASR,EAAKS,QAGnD,MAjBC,IAAIF,UAAWC,EAAQ,WAAYP,GAkB5C,8eC/CIU,uDAAQC,CAAQ,4BAkBpB,SAASH,EAAOI,EAAYC,EAAKd,EAAMe,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMP,EAAWU,OACjBZ,EAAO,wBAAyBS,GAEnB,IAARA,EAEJ,OADAT,EAAO,qCACAK,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAEZE,EAAO,wBAAyBQ,GAChCR,EAAO,0BAA2BI,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdf,EAAO,kBAAmBkB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,GAPC,CAQD,CA5BDjB,EAAO,6BADPU,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJf,EAAO,2BAA4Be,EAAMM,SAClChB,EAAMU,KAGdf,EAAO,0CADPM,GAAS,EACgDG,GACpDC,EAAM,EACHG,IAEHP,IAAUG,GACdT,EAAO,qCACAK,EAAM,KAAMF,SAFpB,EAIA,CACF,CCzCA,SAASmB,EAAShC,EAASc,GAC1B,IAAIf,EACAkC,EACAC,EAGJ,GADAnC,EAAO,CAAA,EACFoC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMnC,EAAUC,EAAMC,GAErB,MAAMiC,EAEPC,EAAIpB,CACN,MACEoB,EAAIlC,EAEL,IAAMoC,EAAYF,GACjB,MAAM,IAAI5B,UAAWC,EAAQ,WAAY2B,IAU1C,YARqB,IAAhBnC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ6B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIN,UAAWC,EAAQ,WAAYK,IAE1C,IAAMwB,EAAYrB,GACjB,MAAM,IAAIT,UAAWC,EAAQ,WAAYQ,IAE1C,OAAOP,EAAOI,EAAY2B,EAASxC,EAAMmC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,EACZ,GACD,CACF,CC1EA,SAASyB,EAAkB1B,EAAY2B,EAASvC,EAASc,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAShC,EAATgC,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAShC,EAASc,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,EAC/C,CClBA0B,EAAAC,EAAA,UAAAV"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 5db7d42..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 2354d41f43afd6077030be96df3b85fb1a194cf2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 2 Nov 2023 13:37:07 +0000 Subject: [PATCH 078/147] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 47 +- benchmark/benchmark.factory.js | 73 - benchmark/benchmark.js | 160 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 224 - docs/types/test.ts | 166 - examples/index.js | 55 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 164 - lib/index.js | 77 - lib/limit.js | 142 - lib/main.js | 95 - lib/validate.js | 80 - package.json | 64 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 1095 ---- test/test.js | 38 - test/test.main.js | 1035 ---- test/test.validate.js | 181 - 49 files changed, 6208 insertions(+), 6947 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/limit.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 26461bb..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-11-01T02:55:50.403Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1e08946..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 5358060..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 372758f..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '37 1 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -458,7 +457,7 @@ reduceRightAsync( files, acc, read, done ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -526,11 +525,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right +[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right/tree/esm -[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce +[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/tree/esm diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 46d8b83..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var reduceRightAsync; - var arr; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - reduceRightAsync = factory( onItem ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - var acc; - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 6ad0714..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var reduceRightAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=false', function benchmark( b ) { - var opts; - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'series': false - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var arr; - var len; - var acc; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'limit': 3 - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index acfc6d6..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right" -%% click B href "https://github.com/stdlib-js/utils-async-reduce-right/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-reduce-right/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-reduce-right/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-reduce-right/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right -[production-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 47a072e..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import reduceRightAsync from '../docs/types/index'; -export = reduceRightAsync; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 530ca4d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var c=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var x=c(function(U,O){ -var R=require('@stdlib/assert-is-plain-object/dist'),h=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,k=require('@stdlib/assert-is-positive-integer/dist').isPrimitive,d=require('@stdlib/error-tools-fmtprodmsg/dist');function I(e,r){return R(r)?(h(r,"thisArg")&&(e.thisArg=r.thisArg),h(r,"series")&&(e.series=r.series,!j(e.series))?new TypeError(d('1RZ2o',"series",e.series)):h(r,"limit")&&(e.limit=r.limit,!k(e.limit))?new TypeError(d('1RZ3P',"limit",e.limit)):null):new TypeError(d('1RZ2V',r));}O.exports=I -});var P=c(function(W,E){ -var J=require("debug"),a=J("reduce-right-async:limit");function L(e,r,i,t,s){var f,m,v,n,u,g;if(n=e.length,a("Collection length: %d",n),n===0)return a("Finished processing a collection."),s(null,r);for(n0&&o();function o(){u-=1,a("Collection element %d: %s.",u,JSON.stringify(e[u])),t.length===3?t.call(i.thisArg,r,e[u],l):t.length===4?t.call(i.thisArg,r,e[u],u,l):t.call(i.thisArg,r,e[u],u,e,l);function l(w,A){if(!m){if(w)return m=!0,b(w);a("Accumulator: %s",JSON.stringify(A)),r=A,b()}}}function b(l){if(l)return a("Encountered an error: %s",l.message),s(l);if(f+=1,a("Processed %d of %d collection elements.",f,n),u>0)return o();if(f===n)return a("Finished processing a collection."),s(null,r)}}E.exports=L -});var q=c(function(X,F){ -var T=require('@stdlib/assert-is-function/dist'),S=require('@stdlib/assert-is-collection/dist'),y=require('@stdlib/error-tools-fmtprodmsg/dist'),B=require('@stdlib/constants-float64-pinf/dist'),z=x(),D=P();function G(e,r){var i,t,s;if(i={},arguments.length>1){if(t=z(i,e),t)throw t;s=r}else s=e;if(!T(s))throw new TypeError(y('1RZ3q',s));return i.series===void 0&&i.limit===void 0&&(i.series=!0),i.series?i.limit=1:i.limit||(i.limit=B),f;function f(m,v,n){if(!S(m))throw new TypeError(y('1RZAh',m));if(!T(n))throw new TypeError(y('1RZ3q',n));return D(m,v,i,s,u);function u(g,o){if(g)return n(g);n(null,o)}}}F.exports=G -});var N=c(function(Y,C){ -var p=q();function H(e,r,i,t,s){if(arguments.length<5)return p(i)(e,r,t);p(i,t)(e,r,s)}C.exports=H -});var K=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),V=N(),M=q();K(V,"factory",M);module.exports=V; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index acb9d67..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/limit.js", "../lib/factory.js", "../lib/main.js", "../lib/index.js"], - "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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\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 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 to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\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 === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, 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 ( !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, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\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* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nmodule.exports = reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' );\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, 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"], - "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,0BAA2B,EAkB/C,SAASE,EAAOC,EAAYC,EAAKC,EAAMC,EAAKC,EAAO,CAClD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMR,EAAW,OACjBF,EAAO,wBAAyBU,CAAI,EAE/BA,IAAQ,EACZ,OAAAV,EAAO,mCAAoC,EACpCM,EAAM,KAAMH,CAAI,EAYxB,IAVKO,EAAMN,EAAK,MACfK,EAAMC,EAEND,EAAML,EAAK,MAEZJ,EAAO,wBAAyBS,CAAI,EACpCT,EAAO,0BAA2BK,EAAI,MAAO,EAE7CE,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVE,EAAK,EAQP,SAASA,GAAO,CACfF,GAAO,EACPX,EAAO,6BAA8BW,EAAK,KAAK,UAAWT,EAAYS,CAAI,CAAE,CAAE,EACzEN,EAAI,SAAW,EACnBA,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGG,CAAG,EACxCT,EAAI,SAAW,EAC1BA,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGA,EAAKG,CAAG,EAExDT,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGA,EAAKT,EAAYY,CAAG,EAUrE,SAASA,EAAIC,EAAOC,EAAS,CAC5B,GAAK,CAAAR,EAIL,IAAKO,EACJ,OAAAP,EAAM,GACCS,EAAMF,CAAM,EAEpBf,EAAO,kBAAmB,KAAK,UAAWgB,CAAO,CAAE,EACnDb,EAAMa,EACNC,EAAK,EACN,CACD,CASA,SAASA,EAAMF,EAAQ,CACtB,GAAKA,EACJ,OAAAf,EAAO,2BAA4Be,EAAM,OAAQ,EAC1CT,EAAMS,CAAM,EAIpB,GAFAR,GAAS,EACTP,EAAO,0CAA2CO,EAAOG,CAAI,EACxDC,EAAM,EACV,OAAOE,EAAK,EAEb,GAAKN,IAAUG,EACd,OAAAV,EAAO,mCAAoC,EACpCM,EAAM,KAAMH,CAAI,CAEzB,CACD,CAKAL,EAAO,QAAUG,IC7IjB,IAAAiB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,gCAAiC,EACjDC,EAAW,IACXC,EAAQ,IAoEZ,SAASC,EAASC,EAASC,EAAM,CAChC,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,CAACP,EAAYW,CAAE,EACnB,MAAM,IAAI,UAAWT,EAAQ,mEAAoES,CAAE,CAAE,EAEtG,OAAKF,EAAK,SAAW,QAAUA,EAAK,QAAU,SAC7CA,EAAK,OAAS,IAEVA,EAAK,OACTA,EAAK,MAAQ,EACDA,EAAK,QACjBA,EAAK,MAAQN,GAEPS,EAaP,SAASA,EAAkBC,EAAYC,EAASC,EAAO,CACtD,GAAK,CAACd,EAAcY,CAAW,EAC9B,MAAM,IAAI,UAAWX,EAAQ,sEAAuEW,CAAW,CAAE,EAElH,GAAK,CAACb,EAAYe,CAAK,EACtB,MAAM,IAAI,UAAWb,EAAQ,mEAAoEa,CAAK,CAAE,EAEzG,OAAOV,EAAOQ,EAAYC,EAASL,EAAME,EAAGK,CAAK,EAUjD,SAASA,EAAMC,EAAOC,EAAM,CAC3B,GAAKD,EACJ,OAAOF,EAAME,CAAM,EAEpBF,EAAM,KAAMG,CAAI,CACjB,CACD,CACD,CAKAnB,EAAO,QAAUO,ICnKjB,IAAAa,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,IA8Dd,SAASC,EAAkBC,EAAYC,EAASC,EAASC,EAAKC,EAAO,CACpE,GAAK,UAAU,OAAS,EACvB,OAAON,EAASI,CAAQ,EAAGF,EAAYC,EAASE,CAAI,EAErDL,EAASI,EAASC,CAAI,EAAGH,EAAYC,EAASG,CAAK,CACpD,CAKAP,EAAO,QAAUE,IC9BjB,IAAIM,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "isPositiveInteger", "format", "validate", "opts", "options", "require_limit", "__commonJSMin", "exports", "module", "logger", "debug", "limit", "collection", "acc", "opts", "fcn", "done", "count", "flg", "lim", "len", "idx", "i", "next", "cb", "error", "result", "clbk", "require_factory", "__commonJSMin", "exports", "module", "isFunction", "isCollection", "format", "PINF", "validate", "limit", "factory", "options", "fcn", "opts", "err", "f", "reduceRightAsync", "collection", "initial", "done", "clbk", "error", "acc", "require_main", "__commonJSMin", "exports", "module", "factory", "reduceRightAsync", "collection", "initial", "options", "fcn", "done", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3f22669..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,224 +0,0 @@ - -{{alias}}( collection, initial, [options,] reducer, done ) - Applies a function against an accumulator and each element in a collection - and returns the accumulated result, iterating from right to left. - - When invoked, `reducer` is provided a maximum of five arguments: - - - `accumulator`: accumulated value - - `value`: collection value - - `index`: collection index - - `collection`: the input collection - - `next`: a callback to be invoked after processing a collection `value` - - The actual number of provided arguments depends on function length. If - `reducer` accepts three arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `next` - - If `reducer` accepts four arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `index` - - `next` - - For every other `reducer` signature, `reducer` is provided all five - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `accumulator`: accumulated value - - If a provided function calls the `next` callback with a truthy `error` - argument, the function suspends execution and immediately calls the `done` - callback for subsequent `error` handling. - - Execution is *not* guaranteed to be asynchronous. To guarantee asynchrony, - 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`). - - The function does not support dynamic collection resizing. - - If provided an empty collection, the function invokes the `done` callback - with the `initial` value as the second argument. - - The function does not skip `undefined` elements. - - When processing collection elements concurrently, *beware* of race - conditions when updating an accumulator. This is especially true when an - accumulator is a primitive (e.g., a number). In general, prefer object - accumulators. - - Parameters - ---------- - collection: Array|TypedArray|Object - Input collection over which to iterate. If provided an object, the - object must be array-like (excluding strings and functions). - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - reducer: Function - The function to invoke for each element in a collection. - - done: Function - A callback invoked either upon processing all collection elements or - upon encountering an error. - - Examples - -------- - // Basic usage: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, fcn, done ) - 3000 - 2500 - 1000 - 6500 - - // Limit number of concurrent invocations: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'limit': 2 }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 2500 - 3000 - 1000 - 6500 - - // Process concurrently: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'series': false }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 1000 - 2500 - 3000 - 6500 - - -{{alias}}.factory( [options,] fcn ) - Returns a function which applies a function against an accumulator and each - element in a collection and returns the accumulated result, iterating from - right to left. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - fcn: Function - The function to invoke for each element in a collection. - - Returns - ------- - out: Function - A function which invokes a function for each element in a collection. - - Examples - -------- - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > var opts = { 'series': false }; - > var f = {{alias}}.factory( opts, fcn ); - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > f( arr, acc, done ) - 1000 - 2500 - 3000 - 6500 - > acc = { 'sum': 0 }; - > arr = [ 1000, 1500, 2000 ]; - > f( arr, acc, done ) - 1000 - 1500 - 2000 - 4500 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index f0001b3..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,166 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unsafe-any */ - -import reduceRightAsync = require( './index' ); - -const reducer = ( acc: any, value: number, index: number, next: Function ) => { - acc.sum += value; - if ( index === void 0 ) { - throw new Error( '`index` is missing.' ); - } - next( null, acc ); -}; - -const done = ( error: Error | null, acc: any ) => { - if ( error ) { - throw error; - } - if ( acc === void 0 ) { - throw new Error( '`acc` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( 2, acc, reducer, done ); // $ExpectError - reduceRightAsync( false, acc, reducer, done ); // $ExpectError - reduceRightAsync( true, acc, reducer, done ); // $ExpectError - reduceRightAsync( {}, acc, reducer, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a predicate argument which is not a predicate function... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 2, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, false, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, true, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 'abc', done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, [], done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a done callback argument which is not a function having a supported signature... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 2 ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, false ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, true ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 'abc' ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, {} ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, [] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const acc = { 'sum': 0 }; - reduceRightAsync(); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, reducer, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - reduceRightAsync.factory( reducer ); // $ExpectType FactoryFunction - reduceRightAsync.factory( { 'series': true }, reducer ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - reduceRightAsync.factory( [], reducer ); // $ExpectError - reduceRightAsync.factory( 123, reducer ); // $ExpectError - reduceRightAsync.factory( 'abc', reducer ); // $ExpectError - reduceRightAsync.factory( false, reducer ); // $ExpectError - reduceRightAsync.factory( true, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not a predicate function... -{ - reduceRightAsync.factory( {} ); // $ExpectError - reduceRightAsync.factory( true ); // $ExpectError - reduceRightAsync.factory( false ); // $ExpectError - reduceRightAsync.factory( {}, 123 ); // $ExpectError - reduceRightAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1( 12, acc, done ); // $ExpectError - fcn1( true, acc, done ); // $ExpectError - fcn1( false, acc, done ); // $ExpectError - fcn1( {}, acc, done ); // $ExpectError - - fcn1( [ 3000, 2500, 1000 ], acc, 12 ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, true ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, false ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, '5' ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, {} ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, [] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1(); // $ExpectError - fcn1( [ 3000, 2500, 1000 ] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - reduceRightAsync.factory( { 'limit': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': true }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': false }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - reduceRightAsync.factory( { 'series': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': 12 }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - reduceRightAsync.factory(); // $ExpectError - reduceRightAsync.factory( {}, reducer, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index dd64345..0000000 --- a/examples/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var resolve = require( 'path' ).resolve; -var readFile = require( '@stdlib/fs-read-file' ); -var reduceRightAsync = require( './../lib' ); - -var files = [ - resolve( __dirname, '..', 'package.json' ), - resolve( __dirname, '..', 'README.md' ) -]; - -function done( error, acc ) { - if ( error ) { - throw error; - } - console.log( acc.count ); -} - -function read( acc, file, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( file, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( null, acc ); - } - acc.count += 1; - next( null, acc ); - } -} - -var acc = { - 'count': 0 -}; -reduceRightAsync( files, acc, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 80786cf..2657f80 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..2c6cb00 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import{isPrimitive as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.1.0-esm/index.mjs";function m(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("1RZ2o,GE","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!d(e.limit))?new TypeError(r("1RZ3P,Fv","limit",e.limit)):null):new TypeError(r("1RZ2V,FD",t))}function c(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){if(this instanceof e){var i=[null];i.push.apply(i,arguments);var r=Function.bind.apply(t,i);return new r}return t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var f=c(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function p(e,t,i,r,s){var n,o,l,d,m,c;if(d=e.length,f("Collection length: %d",d),0===d)return f("Finished processing a collection."),s(null,t);for(l=d0&&p();function p(){function s(e,i){if(!o){if(e)return o=!0,u(e);f("Accumulator: %s",JSON.stringify(i)),t=i,u()}}f("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function u(e){return e?(f("Encountered an error: %s",e.message),s(e)):(f("Processed %d of %d collection elements.",n+=1,d),m>0?p():n===d?(f("Finished processing a collection."),s(null,t)):void 0)}}function u(e,n){var o,l,d;if(o={},arguments.length>1){if(l=m(o,e))throw l;d=n}else d=e;if(!t(d))throw new TypeError(r("1RZ3q,JV",d));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=s),c;function c(e,s,n){if(!i(e))throw new TypeError(r("1RZAh,O3",e));if(!t(n))throw new TypeError(r("1RZ3q,JV",n));return p(e,s,o,d,(function(e,t){if(e)return n(e);n(null,t)}))}}function a(e,t,i,r,s){if(arguments.length<5)return u(i)(e,t,r);u(i,r)(e,t,s)}e(a,"factory",u);export{a as default,u as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..655de94 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '1RZ2V,FD', 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( '1RZ2o,GE', '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( '1RZ3P,Fv', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RZ3q,JV', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '1RZAh,O3', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RZ3q,JV', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","logger","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly","main"],"mappings":";;w5BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,WAAY,SAAUR,EAAKK,SAGtDF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,WAAY,QAASR,EAAKS,QAGnD,MAjBC,IAAIF,UAAWC,EAAQ,WAAYP,GAkB5C,8eC/CIU,uDAAQC,CAAQ,4BAkBpB,SAASH,EAAOI,EAAYC,EAAKd,EAAMe,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMP,EAAWU,OACjBZ,EAAO,wBAAyBS,GAEnB,IAARA,EAEJ,OADAT,EAAO,qCACAK,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAEZE,EAAO,wBAAyBQ,GAChCR,EAAO,0BAA2BI,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdf,EAAO,kBAAmBkB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,GAPC,CAQD,CA5BDjB,EAAO,6BADPU,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJf,EAAO,2BAA4Be,EAAMM,SAClChB,EAAMU,KAGdf,EAAO,0CADPM,GAAS,EACgDG,GACpDC,EAAM,EACHG,IAEHP,IAAUG,GACdT,EAAO,qCACAK,EAAM,KAAMF,SAFpB,EAIA,CACF,CCzCA,SAASmB,EAAShC,EAASc,GAC1B,IAAIf,EACAkC,EACAC,EAGJ,GADAnC,EAAO,CAAA,EACFoC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMnC,EAAUC,EAAMC,GAErB,MAAMiC,EAEPC,EAAIpB,CACN,MACEoB,EAAIlC,EAEL,IAAMoC,EAAYF,GACjB,MAAM,IAAI5B,UAAWC,EAAQ,WAAY2B,IAU1C,YARqB,IAAhBnC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ6B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIN,UAAWC,EAAQ,WAAYK,IAE1C,IAAMwB,EAAYrB,GACjB,MAAM,IAAIT,UAAWC,EAAQ,WAAYQ,IAE1C,OAAOP,EAAOI,EAAY2B,EAASxC,EAAMmC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,EACZ,GACD,CACF,CC1EA,SAASyB,EAAkB1B,EAAY2B,EAASvC,EAASc,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAShC,EAATgC,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAShC,EAASc,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,EAC/C,CClBA0B,EAAAC,EAAA,UAAAV"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 1cd0d47..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,164 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var validate = require( './validate.js' ); -var limit = require( './limit.js' ); - - -// MAIN // - -/** -* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} last argument must be a function -* @returns {Function} function which invokes the provided function once for each element in a collection -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error, data ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var opts = { -* 'series': false -* }; -* -* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: -* var reduceRightAsync = factory( opts, read ); -* -* // Create a collection over which to iterate: -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* // Define a callback which handles errors: -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* // Run `read` for each element in `files`: -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, done ); -*/ -function factory( options, fcn ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = fcn; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '1RZ3q,JV', f ) ); - } - if ( opts.series === void 0 && opts.limit === void 0 ) { - opts.series = true; - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return reduceRightAsync; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * @private - * @param {Collection} collection - input collection - * @param {*} initial - initial value - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be a collection - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function reduceRightAsync( collection, initial, done ) { - if ( !isCollection( collection ) ) { - throw new TypeError( format( '1RZAh,O3', collection ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '1RZ3q,JV', done ) ); - } - return limit( collection, initial, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {*} [acc] - accumulated value - * @returns {void} - */ - function clbk( error, acc ) { - if ( error ) { - return done( error ); - } - done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ae657ff..0000000 --- a/lib/index.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* @module @stdlib/utils-async-reduce-right -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' ); -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/limit.js b/lib/limit.js deleted file mode 100644 index cdb60af..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); - - -// VARIABLES // - -var debug = logger( 'reduce-right-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each element in a collection, limiting the number of concurrently pending functions and iterating from right to left. -* -* @private -* @param {Collection} collection - input collection -* @param {*} acc - initial value -* @param {Options} opts - function options -* @param {*} [opts.thisArg] - execution context -* @param {PositiveInteger} [opts.limit] - maximum number of pending function invocations -* @param {Function} fcn - function to invoke -* @param {Callback} done - function to invoke upon completion or upon encountering an error -* @returns {void} -*/ -function limit( collection, acc, opts, fcn, done ) { - var count; - var flg; - var lim; - var len; - var idx; - var i; - - len = collection.length; - debug( 'Collection length: %d', len ); - - if ( len === 0 ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - count = 0; - idx = len; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all collection elements... - if ( idx > 0 ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next element in a collection. - * - * @private - */ - function next() { - idx -= 1; - debug( 'Collection element %d: %s.', idx, JSON.stringify( collection[ idx ] ) ); - if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], cb ); - } else if ( fcn.length === 4 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, cb ); - } else { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len - } - /** - * Callback invoked once a provided function finishes processing a collection element. - * - * @private - * @param {*} [error] - error - * @param {*} [result] - accumulation result - * @returns {void} - */ - function cb( error, result ) { - if ( flg ) { - // Prevent further processing of collection elements: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Accumulator: %s', JSON.stringify( result ) ); - acc = result; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next collection element. - * - * @private - * @param {*} [error] - error - * @returns {void} - */ - function clbk( error ) { - if ( error ) { - debug( 'Encountered an error: %s', error.message ); - return done( error ); - } - count += 1; - debug( 'Processed %d of %d collection elements.', count, len ); - if ( idx > 0 ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index c8b0d0f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param {Collection} collection - input collection -* @param {*} initial - initial value -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} second-to-last argument must be a function -* @throws {TypeError} last argument must be a function -* @returns {void} -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -function reduceRightAsync( collection, initial, options, fcn, done ) { - if ( arguments.length < 5 ) { - return factory( options )( collection, initial, fcn ); - } - factory( options, fcn )( collection, initial, done ); -} - - -// EXPORTS // - -module.exports = reduceRightAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index c90c17f..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @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 -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'thisArg': {}, -* 'series': false, -* 'limit': 10 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '1RZ2V,FD', options ) ); - } - if ( hasOwnProp( options, 'thisArg' ) ) { - opts.thisArg = options.thisArg; - } - if ( hasOwnProp( options, 'series' ) ) { - opts.series = options.series; - if ( !isBoolean( opts.series ) ) { - return new TypeError( format( '1RZ2o,GE', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '1RZ3P,Fv', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index eda8c17..d4f9525 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,43 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-boolean": "^0.1.1", - "@stdlib/assert-is-collection": "^0.1.0", - "@stdlib/assert-is-function": "^0.1.1", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/assert-is-positive-integer": "^0.1.0", - "@stdlib/constants-float64-pinf": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.1.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/bench": "^0.1.0", - "@stdlib/constants-float64-eps": "^0.1.1", - "@stdlib/fs-read-file": "^0.1.1", - "@stdlib/utils-noop": "^0.1.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..94d4464 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 8244931..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1095 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( {}, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, next ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - factory( opts, next ); - }; - } -}); - -tape( 'the function returns a function (no options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided a collection (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a collection (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (1 argument)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (2 arguments)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with five arguments', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn() { - var value; - var next; - var acc; - var k; - - acc = arguments[ 0 ]; - value = arguments[ 1 ]; - k = arguments[ 2 ]; - next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( k, i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the returned function supports processing collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements concurrently', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 100, 250, 300 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements sequentially (limit = 1)', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of collection elements which are processed at any one time', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 250, 300, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 250, 100, 300 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var reduceRightAsync; - var arr; - - reduceRightAsync = factory( fcn ); - arr = []; - - reduceRightAsync( arr, 0, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var reduceRightAsync; - var obj; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = []; - obj = {}; - reduceRightAsync( arr, obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - i = 0; - - reduceRightAsync( arr, {}, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, acc ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the returned function does not skip empty elements', function test( t ) { - var reduceRightAsync; - var expected; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index f273a40..0000000 --- a/test/test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof reduceRightAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 1893240..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1035 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a collection', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (no options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, next, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, 0 ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - reduceRightAsync( [ 1, 2, 3 ], 0, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (1 argument)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (2 arguments)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with five arguments', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn() { - var next; - var acc; - var v; - - next = arguments[ 4 ]; - acc = arguments[ 0 ]; - v = arguments[ 1 ]; - - i -= 1; - j += 1; - - t.strictEqual( v, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, v ); - - function onTimeout() { - acc.sum += v; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'by default, the function processes collection elements sequentially', function test( t ) { - var values; - var count; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements concurrently', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 100, 250, 300 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': true - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially (limit = 1)', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var arr; - var ctx; - - arr = [ 3, 2, 1 ]; - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 3, 2, 1 ]; - opts = { - 'series': true - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 250, 100, 300 ]; - opts = { - 'limit': 2 - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var arr = []; - reduceRightAsync( arr, 0, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var arr = []; - var obj = {}; - - reduceRightAsync( arr, obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - arr = [ 3, 2, 1 ]; - i = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, value ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the function does not skip empty elements', function test( t ) { - var expected; - var arr; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, fcn, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 7660838..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,181 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `limit` option which is not a positive integer', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - -5, - 0, - 3.14, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'limit': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `series` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'series': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function accepts any value for the `thisArg` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'thisArg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err, null, 'returns null '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'thisArg': {}, - 'series': false, - 'limit': 10 - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From c08c193c927b171793aaed65017c86d876b97055 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 9 Nov 2023 11:41:06 +0000 Subject: [PATCH 079/147] Transform error messages --- lib/factory.js | 8 ++++---- lib/validate.js | 8 ++++---- package.json | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 1125052..1cd0d47 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -22,7 +22,7 @@ var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var PINF = require( '@stdlib/constants-float64-pinf' ); var validate = require( './validate.js' ); var limit = require( './limit.js' ); @@ -109,7 +109,7 @@ function factory( options, fcn ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '1RZ3q,JV', f ) ); } if ( opts.series === void 0 && opts.limit === void 0 ) { opts.series = true; @@ -134,10 +134,10 @@ function factory( options, fcn ) { */ function reduceRightAsync( collection, initial, done ) { if ( !isCollection( collection ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a collection. Value: `%s`.', collection ) ); + throw new TypeError( format( '1RZAh,O3', collection ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '1RZ3q,JV', done ) ); } return limit( collection, initial, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index 9ba927e..c90c17f 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,7 +54,7 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '1RZ2V,FD', options ) ); } if ( hasOwnProp( options, 'thisArg' ) ) { opts.thisArg = options.thisArg; @@ -62,13 +62,13 @@ function validate( opts, options ) { if ( hasOwnProp( options, 'series' ) ) { opts.series = options.series; if ( !isBoolean( opts.series ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'series', opts.series ) ); + return new TypeError( format( '1RZ2o,GE', 'series', opts.series ) ); } } if ( hasOwnProp( options, 'limit' ) ) { opts.limit = options.limit; if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'limit', opts.limit ) ); + return new TypeError( format( '1RZ3P,Fv', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index 69d3886..3b70e02 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-plain-object": "^0.1.1", "@stdlib/assert-is-positive-integer": "^0.1.0", "@stdlib/constants-float64-pinf": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1", "debug": "^2.6.9" From 6f00dbf80891438b1bd0cc2ecdecebb09a7338fe Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 9 Nov 2023 15:25:32 +0000 Subject: [PATCH 080/147] Remove files --- index.d.ts | 410 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6592 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 2657f80..0000000 --- a/index.d.ts +++ /dev/null @@ -1,410 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Execution context. - */ - thisArg?: ThisParameterType>; - - /** - * The maximum number of pending invocations at any one time. - */ - limit?: number; - - /** - * Boolean indicating whether to sequentially invoke the reducer function for each `collection` element. If `true`, the function sets `options.limit=1`. Default: true. - */ - series?: boolean; -} - -/** -* Callback function. -*/ -type Nullary = () => void; - -/** -* Callback function. -* -* @param error - encountered error or null -*/ -type Unary = ( error: Error | null ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Binary = ( error: Error | null, accumulator: U ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param next - a callback to be invoked after processing a collection `value` -*/ -type TernaryReducer = ( this: V, accumulator: U, value: T, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuaternaryReducer = ( this: V, accumulator: U, value: T, index: number, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuinaryReducer = ( this: V, accumulator: U, value: T, index: number, collection: Collection, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type Reducer = TernaryReducer | QuaternaryReducer | QuinaryReducer; - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result. -* -* @param collection - input collection -* @param initial - initial value -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( collection: Collection, initial: U, done: Callback ) => void; - -/** -* Interface for `reduceRightAsync`. -*/ -interface ReduceRightAsync { - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, {}, read, done ); - */ - ( collection: Collection, initial: U, options: Options, reducer: Reducer, done: Callback ): void; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, read, done ); - */ - ( collection: Collection, initial: U, reducer: Reducer, done: Callback ): void; // tslint:disable-line:no-unnecessary-generics - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @throws must provide valid options - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var opts = { - * 'series': false - * }; - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( opts, read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( options: Options, reducer: Reducer ): FactoryFunction; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param reducer - function to invoke for each element in a collection - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( reducer: Reducer ): FactoryFunction; // tslint:disable-line:no-unnecessary-generics -} - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param collection - input collection -* @param initial - initial value -* @param options - function options -* @param options.thisArg - execution context -* @param options.limit - maximum number of pending invocations at any one time -* @param 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 (default: true) -* @param reducer - function to invoke for each element in a collection -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( `@stdlib/fs/read-file` ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -declare var reduceRightAsync: ReduceRightAsync; - - -// EXPORTS // - -export = reduceRightAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 2c6cb00..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import{isPrimitive as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.1.0-esm/index.mjs";function m(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("1RZ2o,GE","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!d(e.limit))?new TypeError(r("1RZ3P,Fv","limit",e.limit)):null):new TypeError(r("1RZ2V,FD",t))}function c(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){if(this instanceof e){var i=[null];i.push.apply(i,arguments);var r=Function.bind.apply(t,i);return new r}return t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var f=c(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function p(e,t,i,r,s){var n,o,l,d,m,c;if(d=e.length,f("Collection length: %d",d),0===d)return f("Finished processing a collection."),s(null,t);for(l=d0&&p();function p(){function s(e,i){if(!o){if(e)return o=!0,u(e);f("Accumulator: %s",JSON.stringify(i)),t=i,u()}}f("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function u(e){return e?(f("Encountered an error: %s",e.message),s(e)):(f("Processed %d of %d collection elements.",n+=1,d),m>0?p():n===d?(f("Finished processing a collection."),s(null,t)):void 0)}}function u(e,n){var o,l,d;if(o={},arguments.length>1){if(l=m(o,e))throw l;d=n}else d=e;if(!t(d))throw new TypeError(r("1RZ3q,JV",d));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=s),c;function c(e,s,n){if(!i(e))throw new TypeError(r("1RZAh,O3",e));if(!t(n))throw new TypeError(r("1RZ3q,JV",n));return p(e,s,o,d,(function(e,t){if(e)return n(e);n(null,t)}))}}function a(e,t,i,r,s){if(arguments.length<5)return u(i)(e,t,r);u(i,r)(e,t,s)}e(a,"factory",u);export{a as default,u as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 655de94..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '1RZ2V,FD', 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( '1RZ2o,GE', '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( '1RZ3P,Fv', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RZ3q,JV', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '1RZAh,O3', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RZ3q,JV', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","logger","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly","main"],"mappings":";;w5BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,WAAY,SAAUR,EAAKK,SAGtDF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,WAAY,QAASR,EAAKS,QAGnD,MAjBC,IAAIF,UAAWC,EAAQ,WAAYP,GAkB5C,8eC/CIU,uDAAQC,CAAQ,4BAkBpB,SAASH,EAAOI,EAAYC,EAAKd,EAAMe,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMP,EAAWU,OACjBZ,EAAO,wBAAyBS,GAEnB,IAARA,EAEJ,OADAT,EAAO,qCACAK,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAEZE,EAAO,wBAAyBQ,GAChCR,EAAO,0BAA2BI,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdf,EAAO,kBAAmBkB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,GAPC,CAQD,CA5BDjB,EAAO,6BADPU,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJf,EAAO,2BAA4Be,EAAMM,SAClChB,EAAMU,KAGdf,EAAO,0CADPM,GAAS,EACgDG,GACpDC,EAAM,EACHG,IAEHP,IAAUG,GACdT,EAAO,qCACAK,EAAM,KAAMF,SAFpB,EAIA,CACF,CCzCA,SAASmB,EAAShC,EAASc,GAC1B,IAAIf,EACAkC,EACAC,EAGJ,GADAnC,EAAO,CAAA,EACFoC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMnC,EAAUC,EAAMC,GAErB,MAAMiC,EAEPC,EAAIpB,CACN,MACEoB,EAAIlC,EAEL,IAAMoC,EAAYF,GACjB,MAAM,IAAI5B,UAAWC,EAAQ,WAAY2B,IAU1C,YARqB,IAAhBnC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ6B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIN,UAAWC,EAAQ,WAAYK,IAE1C,IAAMwB,EAAYrB,GACjB,MAAM,IAAIT,UAAWC,EAAQ,WAAYQ,IAE1C,OAAOP,EAAOI,EAAY2B,EAASxC,EAAMmC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,EACZ,GACD,CACF,CC1EA,SAASyB,EAAkB1B,EAAY2B,EAASvC,EAASc,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAShC,EAATgC,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAShC,EAASc,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,EAC/C,CClBA0B,EAAAC,EAAA,UAAAV"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 94d4464..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 5f38a075aa472203af2f400f630107cee05e8fb4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 9 Nov 2023 15:26:01 +0000 Subject: [PATCH 081/147] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 47 +- benchmark/benchmark.factory.js | 73 - benchmark/benchmark.js | 160 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 224 - docs/types/test.ts | 166 - examples/index.js | 55 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 164 - lib/index.js | 77 - lib/limit.js | 142 - lib/main.js | 95 - lib/validate.js | 80 - package.json | 64 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 1095 ---- test/test.js | 38 - test/test.main.js | 1035 ---- test/test.validate.js | 181 - 48 files changed, 6208 insertions(+), 6946 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/limit.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1e08946..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 5358060..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 372758f..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '37 1 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -458,7 +457,7 @@ reduceRightAsync( files, acc, read, done ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -526,11 +525,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right +[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right/tree/esm -[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce +[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/tree/esm diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 46d8b83..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var reduceRightAsync; - var arr; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - reduceRightAsync = factory( onItem ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - var acc; - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 6ad0714..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var reduceRightAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=false', function benchmark( b ) { - var opts; - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'series': false - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var arr; - var len; - var acc; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'limit': 3 - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index acfc6d6..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right" -%% click B href "https://github.com/stdlib-js/utils-async-reduce-right/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-reduce-right/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-reduce-right/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-reduce-right/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right -[production-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 47a072e..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import reduceRightAsync from '../docs/types/index'; -export = reduceRightAsync; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 530ca4d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var c=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var x=c(function(U,O){ -var R=require('@stdlib/assert-is-plain-object/dist'),h=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,k=require('@stdlib/assert-is-positive-integer/dist').isPrimitive,d=require('@stdlib/error-tools-fmtprodmsg/dist');function I(e,r){return R(r)?(h(r,"thisArg")&&(e.thisArg=r.thisArg),h(r,"series")&&(e.series=r.series,!j(e.series))?new TypeError(d('1RZ2o',"series",e.series)):h(r,"limit")&&(e.limit=r.limit,!k(e.limit))?new TypeError(d('1RZ3P',"limit",e.limit)):null):new TypeError(d('1RZ2V',r));}O.exports=I -});var P=c(function(W,E){ -var J=require("debug"),a=J("reduce-right-async:limit");function L(e,r,i,t,s){var f,m,v,n,u,g;if(n=e.length,a("Collection length: %d",n),n===0)return a("Finished processing a collection."),s(null,r);for(n0&&o();function o(){u-=1,a("Collection element %d: %s.",u,JSON.stringify(e[u])),t.length===3?t.call(i.thisArg,r,e[u],l):t.length===4?t.call(i.thisArg,r,e[u],u,l):t.call(i.thisArg,r,e[u],u,e,l);function l(w,A){if(!m){if(w)return m=!0,b(w);a("Accumulator: %s",JSON.stringify(A)),r=A,b()}}}function b(l){if(l)return a("Encountered an error: %s",l.message),s(l);if(f+=1,a("Processed %d of %d collection elements.",f,n),u>0)return o();if(f===n)return a("Finished processing a collection."),s(null,r)}}E.exports=L -});var q=c(function(X,F){ -var T=require('@stdlib/assert-is-function/dist'),S=require('@stdlib/assert-is-collection/dist'),y=require('@stdlib/error-tools-fmtprodmsg/dist'),B=require('@stdlib/constants-float64-pinf/dist'),z=x(),D=P();function G(e,r){var i,t,s;if(i={},arguments.length>1){if(t=z(i,e),t)throw t;s=r}else s=e;if(!T(s))throw new TypeError(y('1RZ3q',s));return i.series===void 0&&i.limit===void 0&&(i.series=!0),i.series?i.limit=1:i.limit||(i.limit=B),f;function f(m,v,n){if(!S(m))throw new TypeError(y('1RZAh',m));if(!T(n))throw new TypeError(y('1RZ3q',n));return D(m,v,i,s,u);function u(g,o){if(g)return n(g);n(null,o)}}}F.exports=G -});var N=c(function(Y,C){ -var p=q();function H(e,r,i,t,s){if(arguments.length<5)return p(i)(e,r,t);p(i,t)(e,r,s)}C.exports=H -});var K=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),V=N(),M=q();K(V,"factory",M);module.exports=V; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index acb9d67..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/limit.js", "../lib/factory.js", "../lib/main.js", "../lib/index.js"], - "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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\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 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 to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\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 === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, 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 ( !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, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\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* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nmodule.exports = reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' );\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, 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"], - "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,0BAA2B,EAkB/C,SAASE,EAAOC,EAAYC,EAAKC,EAAMC,EAAKC,EAAO,CAClD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMR,EAAW,OACjBF,EAAO,wBAAyBU,CAAI,EAE/BA,IAAQ,EACZ,OAAAV,EAAO,mCAAoC,EACpCM,EAAM,KAAMH,CAAI,EAYxB,IAVKO,EAAMN,EAAK,MACfK,EAAMC,EAEND,EAAML,EAAK,MAEZJ,EAAO,wBAAyBS,CAAI,EACpCT,EAAO,0BAA2BK,EAAI,MAAO,EAE7CE,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVE,EAAK,EAQP,SAASA,GAAO,CACfF,GAAO,EACPX,EAAO,6BAA8BW,EAAK,KAAK,UAAWT,EAAYS,CAAI,CAAE,CAAE,EACzEN,EAAI,SAAW,EACnBA,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGG,CAAG,EACxCT,EAAI,SAAW,EAC1BA,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGA,EAAKG,CAAG,EAExDT,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGA,EAAKT,EAAYY,CAAG,EAUrE,SAASA,EAAIC,EAAOC,EAAS,CAC5B,GAAK,CAAAR,EAIL,IAAKO,EACJ,OAAAP,EAAM,GACCS,EAAMF,CAAM,EAEpBf,EAAO,kBAAmB,KAAK,UAAWgB,CAAO,CAAE,EACnDb,EAAMa,EACNC,EAAK,EACN,CACD,CASA,SAASA,EAAMF,EAAQ,CACtB,GAAKA,EACJ,OAAAf,EAAO,2BAA4Be,EAAM,OAAQ,EAC1CT,EAAMS,CAAM,EAIpB,GAFAR,GAAS,EACTP,EAAO,0CAA2CO,EAAOG,CAAI,EACxDC,EAAM,EACV,OAAOE,EAAK,EAEb,GAAKN,IAAUG,EACd,OAAAV,EAAO,mCAAoC,EACpCM,EAAM,KAAMH,CAAI,CAEzB,CACD,CAKAL,EAAO,QAAUG,IC7IjB,IAAAiB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,gCAAiC,EACjDC,EAAW,IACXC,EAAQ,IAoEZ,SAASC,EAASC,EAASC,EAAM,CAChC,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,CAACP,EAAYW,CAAE,EACnB,MAAM,IAAI,UAAWT,EAAQ,mEAAoES,CAAE,CAAE,EAEtG,OAAKF,EAAK,SAAW,QAAUA,EAAK,QAAU,SAC7CA,EAAK,OAAS,IAEVA,EAAK,OACTA,EAAK,MAAQ,EACDA,EAAK,QACjBA,EAAK,MAAQN,GAEPS,EAaP,SAASA,EAAkBC,EAAYC,EAASC,EAAO,CACtD,GAAK,CAACd,EAAcY,CAAW,EAC9B,MAAM,IAAI,UAAWX,EAAQ,sEAAuEW,CAAW,CAAE,EAElH,GAAK,CAACb,EAAYe,CAAK,EACtB,MAAM,IAAI,UAAWb,EAAQ,mEAAoEa,CAAK,CAAE,EAEzG,OAAOV,EAAOQ,EAAYC,EAASL,EAAME,EAAGK,CAAK,EAUjD,SAASA,EAAMC,EAAOC,EAAM,CAC3B,GAAKD,EACJ,OAAOF,EAAME,CAAM,EAEpBF,EAAM,KAAMG,CAAI,CACjB,CACD,CACD,CAKAnB,EAAO,QAAUO,ICnKjB,IAAAa,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,IA8Dd,SAASC,EAAkBC,EAAYC,EAASC,EAASC,EAAKC,EAAO,CACpE,GAAK,UAAU,OAAS,EACvB,OAAON,EAASI,CAAQ,EAAGF,EAAYC,EAASE,CAAI,EAErDL,EAASI,EAASC,CAAI,EAAGH,EAAYC,EAASG,CAAK,CACpD,CAKAP,EAAO,QAAUE,IC9BjB,IAAIM,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "isPositiveInteger", "format", "validate", "opts", "options", "require_limit", "__commonJSMin", "exports", "module", "logger", "debug", "limit", "collection", "acc", "opts", "fcn", "done", "count", "flg", "lim", "len", "idx", "i", "next", "cb", "error", "result", "clbk", "require_factory", "__commonJSMin", "exports", "module", "isFunction", "isCollection", "format", "PINF", "validate", "limit", "factory", "options", "fcn", "opts", "err", "f", "reduceRightAsync", "collection", "initial", "done", "clbk", "error", "acc", "require_main", "__commonJSMin", "exports", "module", "factory", "reduceRightAsync", "collection", "initial", "options", "fcn", "done", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3f22669..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,224 +0,0 @@ - -{{alias}}( collection, initial, [options,] reducer, done ) - Applies a function against an accumulator and each element in a collection - and returns the accumulated result, iterating from right to left. - - When invoked, `reducer` is provided a maximum of five arguments: - - - `accumulator`: accumulated value - - `value`: collection value - - `index`: collection index - - `collection`: the input collection - - `next`: a callback to be invoked after processing a collection `value` - - The actual number of provided arguments depends on function length. If - `reducer` accepts three arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `next` - - If `reducer` accepts four arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `index` - - `next` - - For every other `reducer` signature, `reducer` is provided all five - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `accumulator`: accumulated value - - If a provided function calls the `next` callback with a truthy `error` - argument, the function suspends execution and immediately calls the `done` - callback for subsequent `error` handling. - - Execution is *not* guaranteed to be asynchronous. To guarantee asynchrony, - 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`). - - The function does not support dynamic collection resizing. - - If provided an empty collection, the function invokes the `done` callback - with the `initial` value as the second argument. - - The function does not skip `undefined` elements. - - When processing collection elements concurrently, *beware* of race - conditions when updating an accumulator. This is especially true when an - accumulator is a primitive (e.g., a number). In general, prefer object - accumulators. - - Parameters - ---------- - collection: Array|TypedArray|Object - Input collection over which to iterate. If provided an object, the - object must be array-like (excluding strings and functions). - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - reducer: Function - The function to invoke for each element in a collection. - - done: Function - A callback invoked either upon processing all collection elements or - upon encountering an error. - - Examples - -------- - // Basic usage: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, fcn, done ) - 3000 - 2500 - 1000 - 6500 - - // Limit number of concurrent invocations: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'limit': 2 }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 2500 - 3000 - 1000 - 6500 - - // Process concurrently: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'series': false }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 1000 - 2500 - 3000 - 6500 - - -{{alias}}.factory( [options,] fcn ) - Returns a function which applies a function against an accumulator and each - element in a collection and returns the accumulated result, iterating from - right to left. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - fcn: Function - The function to invoke for each element in a collection. - - Returns - ------- - out: Function - A function which invokes a function for each element in a collection. - - Examples - -------- - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > var opts = { 'series': false }; - > var f = {{alias}}.factory( opts, fcn ); - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > f( arr, acc, done ) - 1000 - 2500 - 3000 - 6500 - > acc = { 'sum': 0 }; - > arr = [ 1000, 1500, 2000 ]; - > f( arr, acc, done ) - 1000 - 1500 - 2000 - 4500 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index f0001b3..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,166 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unsafe-any */ - -import reduceRightAsync = require( './index' ); - -const reducer = ( acc: any, value: number, index: number, next: Function ) => { - acc.sum += value; - if ( index === void 0 ) { - throw new Error( '`index` is missing.' ); - } - next( null, acc ); -}; - -const done = ( error: Error | null, acc: any ) => { - if ( error ) { - throw error; - } - if ( acc === void 0 ) { - throw new Error( '`acc` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( 2, acc, reducer, done ); // $ExpectError - reduceRightAsync( false, acc, reducer, done ); // $ExpectError - reduceRightAsync( true, acc, reducer, done ); // $ExpectError - reduceRightAsync( {}, acc, reducer, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a predicate argument which is not a predicate function... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 2, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, false, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, true, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 'abc', done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, [], done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a done callback argument which is not a function having a supported signature... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 2 ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, false ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, true ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 'abc' ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, {} ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, [] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const acc = { 'sum': 0 }; - reduceRightAsync(); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, reducer, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - reduceRightAsync.factory( reducer ); // $ExpectType FactoryFunction - reduceRightAsync.factory( { 'series': true }, reducer ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - reduceRightAsync.factory( [], reducer ); // $ExpectError - reduceRightAsync.factory( 123, reducer ); // $ExpectError - reduceRightAsync.factory( 'abc', reducer ); // $ExpectError - reduceRightAsync.factory( false, reducer ); // $ExpectError - reduceRightAsync.factory( true, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not a predicate function... -{ - reduceRightAsync.factory( {} ); // $ExpectError - reduceRightAsync.factory( true ); // $ExpectError - reduceRightAsync.factory( false ); // $ExpectError - reduceRightAsync.factory( {}, 123 ); // $ExpectError - reduceRightAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1( 12, acc, done ); // $ExpectError - fcn1( true, acc, done ); // $ExpectError - fcn1( false, acc, done ); // $ExpectError - fcn1( {}, acc, done ); // $ExpectError - - fcn1( [ 3000, 2500, 1000 ], acc, 12 ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, true ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, false ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, '5' ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, {} ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, [] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1(); // $ExpectError - fcn1( [ 3000, 2500, 1000 ] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - reduceRightAsync.factory( { 'limit': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': true }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': false }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - reduceRightAsync.factory( { 'series': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': 12 }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - reduceRightAsync.factory(); // $ExpectError - reduceRightAsync.factory( {}, reducer, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index dd64345..0000000 --- a/examples/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var resolve = require( 'path' ).resolve; -var readFile = require( '@stdlib/fs-read-file' ); -var reduceRightAsync = require( './../lib' ); - -var files = [ - resolve( __dirname, '..', 'package.json' ), - resolve( __dirname, '..', 'README.md' ) -]; - -function done( error, acc ) { - if ( error ) { - throw error; - } - console.log( acc.count ); -} - -function read( acc, file, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( file, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( null, acc ); - } - acc.count += 1; - next( null, acc ); - } -} - -var acc = { - 'count': 0 -}; -reduceRightAsync( files, acc, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 80786cf..2657f80 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..2c6cb00 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import{isPrimitive as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.1.0-esm/index.mjs";function m(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("1RZ2o,GE","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!d(e.limit))?new TypeError(r("1RZ3P,Fv","limit",e.limit)):null):new TypeError(r("1RZ2V,FD",t))}function c(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){if(this instanceof e){var i=[null];i.push.apply(i,arguments);var r=Function.bind.apply(t,i);return new r}return t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var f=c(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function p(e,t,i,r,s){var n,o,l,d,m,c;if(d=e.length,f("Collection length: %d",d),0===d)return f("Finished processing a collection."),s(null,t);for(l=d0&&p();function p(){function s(e,i){if(!o){if(e)return o=!0,u(e);f("Accumulator: %s",JSON.stringify(i)),t=i,u()}}f("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function u(e){return e?(f("Encountered an error: %s",e.message),s(e)):(f("Processed %d of %d collection elements.",n+=1,d),m>0?p():n===d?(f("Finished processing a collection."),s(null,t)):void 0)}}function u(e,n){var o,l,d;if(o={},arguments.length>1){if(l=m(o,e))throw l;d=n}else d=e;if(!t(d))throw new TypeError(r("1RZ3q,JV",d));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=s),c;function c(e,s,n){if(!i(e))throw new TypeError(r("1RZAh,O3",e));if(!t(n))throw new TypeError(r("1RZ3q,JV",n));return p(e,s,o,d,(function(e,t){if(e)return n(e);n(null,t)}))}}function a(e,t,i,r,s){if(arguments.length<5)return u(i)(e,t,r);u(i,r)(e,t,s)}e(a,"factory",u);export{a as default,u as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..655de94 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '1RZ2V,FD', 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( '1RZ2o,GE', '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( '1RZ3P,Fv', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RZ3q,JV', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '1RZAh,O3', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RZ3q,JV', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","logger","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly","main"],"mappings":";;w5BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,WAAY,SAAUR,EAAKK,SAGtDF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,WAAY,QAASR,EAAKS,QAGnD,MAjBC,IAAIF,UAAWC,EAAQ,WAAYP,GAkB5C,8eC/CIU,uDAAQC,CAAQ,4BAkBpB,SAASH,EAAOI,EAAYC,EAAKd,EAAMe,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMP,EAAWU,OACjBZ,EAAO,wBAAyBS,GAEnB,IAARA,EAEJ,OADAT,EAAO,qCACAK,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAEZE,EAAO,wBAAyBQ,GAChCR,EAAO,0BAA2BI,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdf,EAAO,kBAAmBkB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,GAPC,CAQD,CA5BDjB,EAAO,6BADPU,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJf,EAAO,2BAA4Be,EAAMM,SAClChB,EAAMU,KAGdf,EAAO,0CADPM,GAAS,EACgDG,GACpDC,EAAM,EACHG,IAEHP,IAAUG,GACdT,EAAO,qCACAK,EAAM,KAAMF,SAFpB,EAIA,CACF,CCzCA,SAASmB,EAAShC,EAASc,GAC1B,IAAIf,EACAkC,EACAC,EAGJ,GADAnC,EAAO,CAAA,EACFoC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMnC,EAAUC,EAAMC,GAErB,MAAMiC,EAEPC,EAAIpB,CACN,MACEoB,EAAIlC,EAEL,IAAMoC,EAAYF,GACjB,MAAM,IAAI5B,UAAWC,EAAQ,WAAY2B,IAU1C,YARqB,IAAhBnC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ6B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIN,UAAWC,EAAQ,WAAYK,IAE1C,IAAMwB,EAAYrB,GACjB,MAAM,IAAIT,UAAWC,EAAQ,WAAYQ,IAE1C,OAAOP,EAAOI,EAAY2B,EAASxC,EAAMmC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,EACZ,GACD,CACF,CC1EA,SAASyB,EAAkB1B,EAAY2B,EAASvC,EAASc,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAShC,EAATgC,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAShC,EAASc,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,EAC/C,CClBA0B,EAAAC,EAAA,UAAAV"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 1cd0d47..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,164 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var validate = require( './validate.js' ); -var limit = require( './limit.js' ); - - -// MAIN // - -/** -* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} last argument must be a function -* @returns {Function} function which invokes the provided function once for each element in a collection -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error, data ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var opts = { -* 'series': false -* }; -* -* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: -* var reduceRightAsync = factory( opts, read ); -* -* // Create a collection over which to iterate: -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* // Define a callback which handles errors: -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* // Run `read` for each element in `files`: -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, done ); -*/ -function factory( options, fcn ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = fcn; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '1RZ3q,JV', f ) ); - } - if ( opts.series === void 0 && opts.limit === void 0 ) { - opts.series = true; - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return reduceRightAsync; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * @private - * @param {Collection} collection - input collection - * @param {*} initial - initial value - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be a collection - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function reduceRightAsync( collection, initial, done ) { - if ( !isCollection( collection ) ) { - throw new TypeError( format( '1RZAh,O3', collection ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '1RZ3q,JV', done ) ); - } - return limit( collection, initial, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {*} [acc] - accumulated value - * @returns {void} - */ - function clbk( error, acc ) { - if ( error ) { - return done( error ); - } - done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ae657ff..0000000 --- a/lib/index.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* @module @stdlib/utils-async-reduce-right -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' ); -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/limit.js b/lib/limit.js deleted file mode 100644 index cdb60af..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); - - -// VARIABLES // - -var debug = logger( 'reduce-right-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each element in a collection, limiting the number of concurrently pending functions and iterating from right to left. -* -* @private -* @param {Collection} collection - input collection -* @param {*} acc - initial value -* @param {Options} opts - function options -* @param {*} [opts.thisArg] - execution context -* @param {PositiveInteger} [opts.limit] - maximum number of pending function invocations -* @param {Function} fcn - function to invoke -* @param {Callback} done - function to invoke upon completion or upon encountering an error -* @returns {void} -*/ -function limit( collection, acc, opts, fcn, done ) { - var count; - var flg; - var lim; - var len; - var idx; - var i; - - len = collection.length; - debug( 'Collection length: %d', len ); - - if ( len === 0 ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - count = 0; - idx = len; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all collection elements... - if ( idx > 0 ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next element in a collection. - * - * @private - */ - function next() { - idx -= 1; - debug( 'Collection element %d: %s.', idx, JSON.stringify( collection[ idx ] ) ); - if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], cb ); - } else if ( fcn.length === 4 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, cb ); - } else { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len - } - /** - * Callback invoked once a provided function finishes processing a collection element. - * - * @private - * @param {*} [error] - error - * @param {*} [result] - accumulation result - * @returns {void} - */ - function cb( error, result ) { - if ( flg ) { - // Prevent further processing of collection elements: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Accumulator: %s', JSON.stringify( result ) ); - acc = result; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next collection element. - * - * @private - * @param {*} [error] - error - * @returns {void} - */ - function clbk( error ) { - if ( error ) { - debug( 'Encountered an error: %s', error.message ); - return done( error ); - } - count += 1; - debug( 'Processed %d of %d collection elements.', count, len ); - if ( idx > 0 ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index c8b0d0f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param {Collection} collection - input collection -* @param {*} initial - initial value -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} second-to-last argument must be a function -* @throws {TypeError} last argument must be a function -* @returns {void} -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -function reduceRightAsync( collection, initial, options, fcn, done ) { - if ( arguments.length < 5 ) { - return factory( options )( collection, initial, fcn ); - } - factory( options, fcn )( collection, initial, done ); -} - - -// EXPORTS // - -module.exports = reduceRightAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index c90c17f..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @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 -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'thisArg': {}, -* 'series': false, -* 'limit': 10 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '1RZ2V,FD', options ) ); - } - if ( hasOwnProp( options, 'thisArg' ) ) { - opts.thisArg = options.thisArg; - } - if ( hasOwnProp( options, 'series' ) ) { - opts.series = options.series; - if ( !isBoolean( opts.series ) ) { - return new TypeError( format( '1RZ2o,GE', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '1RZ3P,Fv', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 3b70e02..d4f9525 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,43 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-boolean": "^0.1.1", - "@stdlib/assert-is-collection": "^0.1.0", - "@stdlib/assert-is-function": "^0.1.1", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/assert-is-positive-integer": "^0.1.0", - "@stdlib/constants-float64-pinf": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.2.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/bench": "^0.2.0", - "@stdlib/constants-float64-eps": "^0.1.1", - "@stdlib/fs-read-file": "^0.1.1", - "@stdlib/utils-noop": "^0.1.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..e4b42ce --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 8244931..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1095 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( {}, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, next ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - factory( opts, next ); - }; - } -}); - -tape( 'the function returns a function (no options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided a collection (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a collection (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (1 argument)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (2 arguments)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with five arguments', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn() { - var value; - var next; - var acc; - var k; - - acc = arguments[ 0 ]; - value = arguments[ 1 ]; - k = arguments[ 2 ]; - next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( k, i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the returned function supports processing collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements concurrently', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 100, 250, 300 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements sequentially (limit = 1)', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of collection elements which are processed at any one time', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 250, 300, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 250, 100, 300 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var reduceRightAsync; - var arr; - - reduceRightAsync = factory( fcn ); - arr = []; - - reduceRightAsync( arr, 0, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var reduceRightAsync; - var obj; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = []; - obj = {}; - reduceRightAsync( arr, obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - i = 0; - - reduceRightAsync( arr, {}, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, acc ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the returned function does not skip empty elements', function test( t ) { - var reduceRightAsync; - var expected; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index f273a40..0000000 --- a/test/test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof reduceRightAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 1893240..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1035 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a collection', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (no options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, next, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, 0 ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - reduceRightAsync( [ 1, 2, 3 ], 0, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (1 argument)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (2 arguments)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with five arguments', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn() { - var next; - var acc; - var v; - - next = arguments[ 4 ]; - acc = arguments[ 0 ]; - v = arguments[ 1 ]; - - i -= 1; - j += 1; - - t.strictEqual( v, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, v ); - - function onTimeout() { - acc.sum += v; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'by default, the function processes collection elements sequentially', function test( t ) { - var values; - var count; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements concurrently', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 100, 250, 300 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': true - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially (limit = 1)', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var arr; - var ctx; - - arr = [ 3, 2, 1 ]; - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 3, 2, 1 ]; - opts = { - 'series': true - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 250, 100, 300 ]; - opts = { - 'limit': 2 - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var arr = []; - reduceRightAsync( arr, 0, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var arr = []; - var obj = {}; - - reduceRightAsync( arr, obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - arr = [ 3, 2, 1 ]; - i = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, value ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the function does not skip empty elements', function test( t ) { - var expected; - var arr; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, fcn, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 7660838..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,181 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `limit` option which is not a positive integer', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - -5, - 0, - 3.14, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'limit': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `series` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'series': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function accepts any value for the `thisArg` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'thisArg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err, null, 'returns null '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'thisArg': {}, - 'series': false, - 'limit': 10 - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From 426bc91f17298ff61b863b721e0555e1e5d3d5de Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 12 Nov 2023 16:04:44 +0000 Subject: [PATCH 082/147] Transform error messages --- lib/factory.js | 8 ++++---- lib/validate.js | 8 ++++---- package.json | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 1125052..1cd0d47 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -22,7 +22,7 @@ var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var PINF = require( '@stdlib/constants-float64-pinf' ); var validate = require( './validate.js' ); var limit = require( './limit.js' ); @@ -109,7 +109,7 @@ function factory( options, fcn ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '1RZ3q,JV', f ) ); } if ( opts.series === void 0 && opts.limit === void 0 ) { opts.series = true; @@ -134,10 +134,10 @@ function factory( options, fcn ) { */ function reduceRightAsync( collection, initial, done ) { if ( !isCollection( collection ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a collection. Value: `%s`.', collection ) ); + throw new TypeError( format( '1RZAh,O3', collection ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '1RZ3q,JV', done ) ); } return limit( collection, initial, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index 9ba927e..c90c17f 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,7 +54,7 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '1RZ2V,FD', options ) ); } if ( hasOwnProp( options, 'thisArg' ) ) { opts.thisArg = options.thisArg; @@ -62,13 +62,13 @@ function validate( opts, options ) { if ( hasOwnProp( options, 'series' ) ) { opts.series = options.series; if ( !isBoolean( opts.series ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'series', opts.series ) ); + return new TypeError( format( '1RZ2o,GE', 'series', opts.series ) ); } } if ( hasOwnProp( options, 'limit' ) ) { opts.limit = options.limit; if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'limit', opts.limit ) ); + return new TypeError( format( '1RZ3P,Fv', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index 69d3886..3b70e02 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-plain-object": "^0.1.1", "@stdlib/assert-is-positive-integer": "^0.1.0", "@stdlib/constants-float64-pinf": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1", "debug": "^2.6.9" From 74cd218ba330f9ca0ded416cc695d6b673e8b852 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 12 Nov 2023 17:29:19 +0000 Subject: [PATCH 083/147] Remove files --- index.d.ts | 410 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6592 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 2657f80..0000000 --- a/index.d.ts +++ /dev/null @@ -1,410 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Execution context. - */ - thisArg?: ThisParameterType>; - - /** - * The maximum number of pending invocations at any one time. - */ - limit?: number; - - /** - * Boolean indicating whether to sequentially invoke the reducer function for each `collection` element. If `true`, the function sets `options.limit=1`. Default: true. - */ - series?: boolean; -} - -/** -* Callback function. -*/ -type Nullary = () => void; - -/** -* Callback function. -* -* @param error - encountered error or null -*/ -type Unary = ( error: Error | null ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Binary = ( error: Error | null, accumulator: U ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param next - a callback to be invoked after processing a collection `value` -*/ -type TernaryReducer = ( this: V, accumulator: U, value: T, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuaternaryReducer = ( this: V, accumulator: U, value: T, index: number, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuinaryReducer = ( this: V, accumulator: U, value: T, index: number, collection: Collection, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type Reducer = TernaryReducer | QuaternaryReducer | QuinaryReducer; - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result. -* -* @param collection - input collection -* @param initial - initial value -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( collection: Collection, initial: U, done: Callback ) => void; - -/** -* Interface for `reduceRightAsync`. -*/ -interface ReduceRightAsync { - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, {}, read, done ); - */ - ( collection: Collection, initial: U, options: Options, reducer: Reducer, done: Callback ): void; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, read, done ); - */ - ( collection: Collection, initial: U, reducer: Reducer, done: Callback ): void; // tslint:disable-line:no-unnecessary-generics - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @throws must provide valid options - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var opts = { - * 'series': false - * }; - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( opts, read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( options: Options, reducer: Reducer ): FactoryFunction; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param reducer - function to invoke for each element in a collection - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( reducer: Reducer ): FactoryFunction; // tslint:disable-line:no-unnecessary-generics -} - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param collection - input collection -* @param initial - initial value -* @param options - function options -* @param options.thisArg - execution context -* @param options.limit - maximum number of pending invocations at any one time -* @param 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 (default: true) -* @param reducer - function to invoke for each element in a collection -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( `@stdlib/fs/read-file` ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -declare var reduceRightAsync: ReduceRightAsync; - - -// EXPORTS // - -export = reduceRightAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 2c6cb00..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import{isPrimitive as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.1.0-esm/index.mjs";function m(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("1RZ2o,GE","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!d(e.limit))?new TypeError(r("1RZ3P,Fv","limit",e.limit)):null):new TypeError(r("1RZ2V,FD",t))}function c(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){if(this instanceof e){var i=[null];i.push.apply(i,arguments);var r=Function.bind.apply(t,i);return new r}return t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var f=c(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function p(e,t,i,r,s){var n,o,l,d,m,c;if(d=e.length,f("Collection length: %d",d),0===d)return f("Finished processing a collection."),s(null,t);for(l=d0&&p();function p(){function s(e,i){if(!o){if(e)return o=!0,u(e);f("Accumulator: %s",JSON.stringify(i)),t=i,u()}}f("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function u(e){return e?(f("Encountered an error: %s",e.message),s(e)):(f("Processed %d of %d collection elements.",n+=1,d),m>0?p():n===d?(f("Finished processing a collection."),s(null,t)):void 0)}}function u(e,n){var o,l,d;if(o={},arguments.length>1){if(l=m(o,e))throw l;d=n}else d=e;if(!t(d))throw new TypeError(r("1RZ3q,JV",d));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=s),c;function c(e,s,n){if(!i(e))throw new TypeError(r("1RZAh,O3",e));if(!t(n))throw new TypeError(r("1RZ3q,JV",n));return p(e,s,o,d,(function(e,t){if(e)return n(e);n(null,t)}))}}function a(e,t,i,r,s){if(arguments.length<5)return u(i)(e,t,r);u(i,r)(e,t,s)}e(a,"factory",u);export{a as default,u as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 655de94..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '1RZ2V,FD', 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( '1RZ2o,GE', '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( '1RZ3P,Fv', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RZ3q,JV', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '1RZAh,O3', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RZ3q,JV', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","logger","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly","main"],"mappings":";;w5BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,WAAY,SAAUR,EAAKK,SAGtDF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,WAAY,QAASR,EAAKS,QAGnD,MAjBC,IAAIF,UAAWC,EAAQ,WAAYP,GAkB5C,8eC/CIU,uDAAQC,CAAQ,4BAkBpB,SAASH,EAAOI,EAAYC,EAAKd,EAAMe,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMP,EAAWU,OACjBZ,EAAO,wBAAyBS,GAEnB,IAARA,EAEJ,OADAT,EAAO,qCACAK,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAEZE,EAAO,wBAAyBQ,GAChCR,EAAO,0BAA2BI,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdf,EAAO,kBAAmBkB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,GAPC,CAQD,CA5BDjB,EAAO,6BADPU,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJf,EAAO,2BAA4Be,EAAMM,SAClChB,EAAMU,KAGdf,EAAO,0CADPM,GAAS,EACgDG,GACpDC,EAAM,EACHG,IAEHP,IAAUG,GACdT,EAAO,qCACAK,EAAM,KAAMF,SAFpB,EAIA,CACF,CCzCA,SAASmB,EAAShC,EAASc,GAC1B,IAAIf,EACAkC,EACAC,EAGJ,GADAnC,EAAO,CAAA,EACFoC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMnC,EAAUC,EAAMC,GAErB,MAAMiC,EAEPC,EAAIpB,CACN,MACEoB,EAAIlC,EAEL,IAAMoC,EAAYF,GACjB,MAAM,IAAI5B,UAAWC,EAAQ,WAAY2B,IAU1C,YARqB,IAAhBnC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ6B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIN,UAAWC,EAAQ,WAAYK,IAE1C,IAAMwB,EAAYrB,GACjB,MAAM,IAAIT,UAAWC,EAAQ,WAAYQ,IAE1C,OAAOP,EAAOI,EAAY2B,EAASxC,EAAMmC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,EACZ,GACD,CACF,CC1EA,SAASyB,EAAkB1B,EAAY2B,EAASvC,EAASc,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAShC,EAATgC,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAShC,EAASc,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,EAC/C,CClBA0B,EAAAC,EAAA,UAAAV"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index e4b42ce..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 45e9a4d9d71e3915c3b696fcc1c1f5065316e752 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 12 Nov 2023 17:29:50 +0000 Subject: [PATCH 084/147] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 47 +- benchmark/benchmark.factory.js | 73 - benchmark/benchmark.js | 160 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 224 - docs/types/test.ts | 166 - examples/index.js | 55 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 164 - lib/index.js | 77 - lib/limit.js | 142 - lib/main.js | 95 - lib/validate.js | 80 - package.json | 64 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 1095 ---- test/test.js | 38 - test/test.main.js | 1035 ---- test/test.validate.js | 181 - 48 files changed, 6208 insertions(+), 6946 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/limit.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1e08946..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 5358060..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 372758f..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '37 1 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -458,7 +457,7 @@ reduceRightAsync( files, acc, read, done ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -526,11 +525,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right +[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right/tree/esm -[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce +[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/tree/esm diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 46d8b83..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var reduceRightAsync; - var arr; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - reduceRightAsync = factory( onItem ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - var acc; - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 6ad0714..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var reduceRightAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=false', function benchmark( b ) { - var opts; - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'series': false - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var arr; - var len; - var acc; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'limit': 3 - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index acfc6d6..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right" -%% click B href "https://github.com/stdlib-js/utils-async-reduce-right/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-reduce-right/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-reduce-right/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-reduce-right/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right -[production-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 47a072e..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import reduceRightAsync from '../docs/types/index'; -export = reduceRightAsync; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 530ca4d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var c=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var x=c(function(U,O){ -var R=require('@stdlib/assert-is-plain-object/dist'),h=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,k=require('@stdlib/assert-is-positive-integer/dist').isPrimitive,d=require('@stdlib/error-tools-fmtprodmsg/dist');function I(e,r){return R(r)?(h(r,"thisArg")&&(e.thisArg=r.thisArg),h(r,"series")&&(e.series=r.series,!j(e.series))?new TypeError(d('1RZ2o',"series",e.series)):h(r,"limit")&&(e.limit=r.limit,!k(e.limit))?new TypeError(d('1RZ3P',"limit",e.limit)):null):new TypeError(d('1RZ2V',r));}O.exports=I -});var P=c(function(W,E){ -var J=require("debug"),a=J("reduce-right-async:limit");function L(e,r,i,t,s){var f,m,v,n,u,g;if(n=e.length,a("Collection length: %d",n),n===0)return a("Finished processing a collection."),s(null,r);for(n0&&o();function o(){u-=1,a("Collection element %d: %s.",u,JSON.stringify(e[u])),t.length===3?t.call(i.thisArg,r,e[u],l):t.length===4?t.call(i.thisArg,r,e[u],u,l):t.call(i.thisArg,r,e[u],u,e,l);function l(w,A){if(!m){if(w)return m=!0,b(w);a("Accumulator: %s",JSON.stringify(A)),r=A,b()}}}function b(l){if(l)return a("Encountered an error: %s",l.message),s(l);if(f+=1,a("Processed %d of %d collection elements.",f,n),u>0)return o();if(f===n)return a("Finished processing a collection."),s(null,r)}}E.exports=L -});var q=c(function(X,F){ -var T=require('@stdlib/assert-is-function/dist'),S=require('@stdlib/assert-is-collection/dist'),y=require('@stdlib/error-tools-fmtprodmsg/dist'),B=require('@stdlib/constants-float64-pinf/dist'),z=x(),D=P();function G(e,r){var i,t,s;if(i={},arguments.length>1){if(t=z(i,e),t)throw t;s=r}else s=e;if(!T(s))throw new TypeError(y('1RZ3q',s));return i.series===void 0&&i.limit===void 0&&(i.series=!0),i.series?i.limit=1:i.limit||(i.limit=B),f;function f(m,v,n){if(!S(m))throw new TypeError(y('1RZAh',m));if(!T(n))throw new TypeError(y('1RZ3q',n));return D(m,v,i,s,u);function u(g,o){if(g)return n(g);n(null,o)}}}F.exports=G -});var N=c(function(Y,C){ -var p=q();function H(e,r,i,t,s){if(arguments.length<5)return p(i)(e,r,t);p(i,t)(e,r,s)}C.exports=H -});var K=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),V=N(),M=q();K(V,"factory",M);module.exports=V; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index acb9d67..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/limit.js", "../lib/factory.js", "../lib/main.js", "../lib/index.js"], - "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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\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 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 to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\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 === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, 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 ( !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, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\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* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nmodule.exports = reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' );\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, 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"], - "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,0BAA2B,EAkB/C,SAASE,EAAOC,EAAYC,EAAKC,EAAMC,EAAKC,EAAO,CAClD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMR,EAAW,OACjBF,EAAO,wBAAyBU,CAAI,EAE/BA,IAAQ,EACZ,OAAAV,EAAO,mCAAoC,EACpCM,EAAM,KAAMH,CAAI,EAYxB,IAVKO,EAAMN,EAAK,MACfK,EAAMC,EAEND,EAAML,EAAK,MAEZJ,EAAO,wBAAyBS,CAAI,EACpCT,EAAO,0BAA2BK,EAAI,MAAO,EAE7CE,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVE,EAAK,EAQP,SAASA,GAAO,CACfF,GAAO,EACPX,EAAO,6BAA8BW,EAAK,KAAK,UAAWT,EAAYS,CAAI,CAAE,CAAE,EACzEN,EAAI,SAAW,EACnBA,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGG,CAAG,EACxCT,EAAI,SAAW,EAC1BA,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGA,EAAKG,CAAG,EAExDT,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGA,EAAKT,EAAYY,CAAG,EAUrE,SAASA,EAAIC,EAAOC,EAAS,CAC5B,GAAK,CAAAR,EAIL,IAAKO,EACJ,OAAAP,EAAM,GACCS,EAAMF,CAAM,EAEpBf,EAAO,kBAAmB,KAAK,UAAWgB,CAAO,CAAE,EACnDb,EAAMa,EACNC,EAAK,EACN,CACD,CASA,SAASA,EAAMF,EAAQ,CACtB,GAAKA,EACJ,OAAAf,EAAO,2BAA4Be,EAAM,OAAQ,EAC1CT,EAAMS,CAAM,EAIpB,GAFAR,GAAS,EACTP,EAAO,0CAA2CO,EAAOG,CAAI,EACxDC,EAAM,EACV,OAAOE,EAAK,EAEb,GAAKN,IAAUG,EACd,OAAAV,EAAO,mCAAoC,EACpCM,EAAM,KAAMH,CAAI,CAEzB,CACD,CAKAL,EAAO,QAAUG,IC7IjB,IAAAiB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,gCAAiC,EACjDC,EAAW,IACXC,EAAQ,IAoEZ,SAASC,EAASC,EAASC,EAAM,CAChC,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,CAACP,EAAYW,CAAE,EACnB,MAAM,IAAI,UAAWT,EAAQ,mEAAoES,CAAE,CAAE,EAEtG,OAAKF,EAAK,SAAW,QAAUA,EAAK,QAAU,SAC7CA,EAAK,OAAS,IAEVA,EAAK,OACTA,EAAK,MAAQ,EACDA,EAAK,QACjBA,EAAK,MAAQN,GAEPS,EAaP,SAASA,EAAkBC,EAAYC,EAASC,EAAO,CACtD,GAAK,CAACd,EAAcY,CAAW,EAC9B,MAAM,IAAI,UAAWX,EAAQ,sEAAuEW,CAAW,CAAE,EAElH,GAAK,CAACb,EAAYe,CAAK,EACtB,MAAM,IAAI,UAAWb,EAAQ,mEAAoEa,CAAK,CAAE,EAEzG,OAAOV,EAAOQ,EAAYC,EAASL,EAAME,EAAGK,CAAK,EAUjD,SAASA,EAAMC,EAAOC,EAAM,CAC3B,GAAKD,EACJ,OAAOF,EAAME,CAAM,EAEpBF,EAAM,KAAMG,CAAI,CACjB,CACD,CACD,CAKAnB,EAAO,QAAUO,ICnKjB,IAAAa,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,IA8Dd,SAASC,EAAkBC,EAAYC,EAASC,EAASC,EAAKC,EAAO,CACpE,GAAK,UAAU,OAAS,EACvB,OAAON,EAASI,CAAQ,EAAGF,EAAYC,EAASE,CAAI,EAErDL,EAASI,EAASC,CAAI,EAAGH,EAAYC,EAASG,CAAK,CACpD,CAKAP,EAAO,QAAUE,IC9BjB,IAAIM,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "isPositiveInteger", "format", "validate", "opts", "options", "require_limit", "__commonJSMin", "exports", "module", "logger", "debug", "limit", "collection", "acc", "opts", "fcn", "done", "count", "flg", "lim", "len", "idx", "i", "next", "cb", "error", "result", "clbk", "require_factory", "__commonJSMin", "exports", "module", "isFunction", "isCollection", "format", "PINF", "validate", "limit", "factory", "options", "fcn", "opts", "err", "f", "reduceRightAsync", "collection", "initial", "done", "clbk", "error", "acc", "require_main", "__commonJSMin", "exports", "module", "factory", "reduceRightAsync", "collection", "initial", "options", "fcn", "done", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3f22669..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,224 +0,0 @@ - -{{alias}}( collection, initial, [options,] reducer, done ) - Applies a function against an accumulator and each element in a collection - and returns the accumulated result, iterating from right to left. - - When invoked, `reducer` is provided a maximum of five arguments: - - - `accumulator`: accumulated value - - `value`: collection value - - `index`: collection index - - `collection`: the input collection - - `next`: a callback to be invoked after processing a collection `value` - - The actual number of provided arguments depends on function length. If - `reducer` accepts three arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `next` - - If `reducer` accepts four arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `index` - - `next` - - For every other `reducer` signature, `reducer` is provided all five - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `accumulator`: accumulated value - - If a provided function calls the `next` callback with a truthy `error` - argument, the function suspends execution and immediately calls the `done` - callback for subsequent `error` handling. - - Execution is *not* guaranteed to be asynchronous. To guarantee asynchrony, - 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`). - - The function does not support dynamic collection resizing. - - If provided an empty collection, the function invokes the `done` callback - with the `initial` value as the second argument. - - The function does not skip `undefined` elements. - - When processing collection elements concurrently, *beware* of race - conditions when updating an accumulator. This is especially true when an - accumulator is a primitive (e.g., a number). In general, prefer object - accumulators. - - Parameters - ---------- - collection: Array|TypedArray|Object - Input collection over which to iterate. If provided an object, the - object must be array-like (excluding strings and functions). - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - reducer: Function - The function to invoke for each element in a collection. - - done: Function - A callback invoked either upon processing all collection elements or - upon encountering an error. - - Examples - -------- - // Basic usage: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, fcn, done ) - 3000 - 2500 - 1000 - 6500 - - // Limit number of concurrent invocations: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'limit': 2 }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 2500 - 3000 - 1000 - 6500 - - // Process concurrently: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'series': false }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 1000 - 2500 - 3000 - 6500 - - -{{alias}}.factory( [options,] fcn ) - Returns a function which applies a function against an accumulator and each - element in a collection and returns the accumulated result, iterating from - right to left. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - fcn: Function - The function to invoke for each element in a collection. - - Returns - ------- - out: Function - A function which invokes a function for each element in a collection. - - Examples - -------- - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > var opts = { 'series': false }; - > var f = {{alias}}.factory( opts, fcn ); - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > f( arr, acc, done ) - 1000 - 2500 - 3000 - 6500 - > acc = { 'sum': 0 }; - > arr = [ 1000, 1500, 2000 ]; - > f( arr, acc, done ) - 1000 - 1500 - 2000 - 4500 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index f0001b3..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,166 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unsafe-any */ - -import reduceRightAsync = require( './index' ); - -const reducer = ( acc: any, value: number, index: number, next: Function ) => { - acc.sum += value; - if ( index === void 0 ) { - throw new Error( '`index` is missing.' ); - } - next( null, acc ); -}; - -const done = ( error: Error | null, acc: any ) => { - if ( error ) { - throw error; - } - if ( acc === void 0 ) { - throw new Error( '`acc` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( 2, acc, reducer, done ); // $ExpectError - reduceRightAsync( false, acc, reducer, done ); // $ExpectError - reduceRightAsync( true, acc, reducer, done ); // $ExpectError - reduceRightAsync( {}, acc, reducer, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a predicate argument which is not a predicate function... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 2, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, false, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, true, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 'abc', done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, [], done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a done callback argument which is not a function having a supported signature... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 2 ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, false ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, true ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 'abc' ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, {} ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, [] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const acc = { 'sum': 0 }; - reduceRightAsync(); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, reducer, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - reduceRightAsync.factory( reducer ); // $ExpectType FactoryFunction - reduceRightAsync.factory( { 'series': true }, reducer ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - reduceRightAsync.factory( [], reducer ); // $ExpectError - reduceRightAsync.factory( 123, reducer ); // $ExpectError - reduceRightAsync.factory( 'abc', reducer ); // $ExpectError - reduceRightAsync.factory( false, reducer ); // $ExpectError - reduceRightAsync.factory( true, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not a predicate function... -{ - reduceRightAsync.factory( {} ); // $ExpectError - reduceRightAsync.factory( true ); // $ExpectError - reduceRightAsync.factory( false ); // $ExpectError - reduceRightAsync.factory( {}, 123 ); // $ExpectError - reduceRightAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1( 12, acc, done ); // $ExpectError - fcn1( true, acc, done ); // $ExpectError - fcn1( false, acc, done ); // $ExpectError - fcn1( {}, acc, done ); // $ExpectError - - fcn1( [ 3000, 2500, 1000 ], acc, 12 ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, true ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, false ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, '5' ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, {} ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, [] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1(); // $ExpectError - fcn1( [ 3000, 2500, 1000 ] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - reduceRightAsync.factory( { 'limit': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': true }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': false }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - reduceRightAsync.factory( { 'series': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': 12 }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - reduceRightAsync.factory(); // $ExpectError - reduceRightAsync.factory( {}, reducer, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index dd64345..0000000 --- a/examples/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var resolve = require( 'path' ).resolve; -var readFile = require( '@stdlib/fs-read-file' ); -var reduceRightAsync = require( './../lib' ); - -var files = [ - resolve( __dirname, '..', 'package.json' ), - resolve( __dirname, '..', 'README.md' ) -]; - -function done( error, acc ) { - if ( error ) { - throw error; - } - console.log( acc.count ); -} - -function read( acc, file, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( file, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( null, acc ); - } - acc.count += 1; - next( null, acc ); - } -} - -var acc = { - 'count': 0 -}; -reduceRightAsync( files, acc, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 16e0539..816cbe3 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..2c6cb00 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import{isPrimitive as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.1.0-esm/index.mjs";function m(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("1RZ2o,GE","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!d(e.limit))?new TypeError(r("1RZ3P,Fv","limit",e.limit)):null):new TypeError(r("1RZ2V,FD",t))}function c(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){if(this instanceof e){var i=[null];i.push.apply(i,arguments);var r=Function.bind.apply(t,i);return new r}return t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var f=c(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function p(e,t,i,r,s){var n,o,l,d,m,c;if(d=e.length,f("Collection length: %d",d),0===d)return f("Finished processing a collection."),s(null,t);for(l=d0&&p();function p(){function s(e,i){if(!o){if(e)return o=!0,u(e);f("Accumulator: %s",JSON.stringify(i)),t=i,u()}}f("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function u(e){return e?(f("Encountered an error: %s",e.message),s(e)):(f("Processed %d of %d collection elements.",n+=1,d),m>0?p():n===d?(f("Finished processing a collection."),s(null,t)):void 0)}}function u(e,n){var o,l,d;if(o={},arguments.length>1){if(l=m(o,e))throw l;d=n}else d=e;if(!t(d))throw new TypeError(r("1RZ3q,JV",d));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=s),c;function c(e,s,n){if(!i(e))throw new TypeError(r("1RZAh,O3",e));if(!t(n))throw new TypeError(r("1RZ3q,JV",n));return p(e,s,o,d,(function(e,t){if(e)return n(e);n(null,t)}))}}function a(e,t,i,r,s){if(arguments.length<5)return u(i)(e,t,r);u(i,r)(e,t,s)}e(a,"factory",u);export{a as default,u as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..655de94 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '1RZ2V,FD', 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( '1RZ2o,GE', '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( '1RZ3P,Fv', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RZ3q,JV', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '1RZAh,O3', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RZ3q,JV', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","logger","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly","main"],"mappings":";;w5BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,WAAY,SAAUR,EAAKK,SAGtDF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,WAAY,QAASR,EAAKS,QAGnD,MAjBC,IAAIF,UAAWC,EAAQ,WAAYP,GAkB5C,8eC/CIU,uDAAQC,CAAQ,4BAkBpB,SAASH,EAAOI,EAAYC,EAAKd,EAAMe,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMP,EAAWU,OACjBZ,EAAO,wBAAyBS,GAEnB,IAARA,EAEJ,OADAT,EAAO,qCACAK,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAEZE,EAAO,wBAAyBQ,GAChCR,EAAO,0BAA2BI,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdf,EAAO,kBAAmBkB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,GAPC,CAQD,CA5BDjB,EAAO,6BADPU,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJf,EAAO,2BAA4Be,EAAMM,SAClChB,EAAMU,KAGdf,EAAO,0CADPM,GAAS,EACgDG,GACpDC,EAAM,EACHG,IAEHP,IAAUG,GACdT,EAAO,qCACAK,EAAM,KAAMF,SAFpB,EAIA,CACF,CCzCA,SAASmB,EAAShC,EAASc,GAC1B,IAAIf,EACAkC,EACAC,EAGJ,GADAnC,EAAO,CAAA,EACFoC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMnC,EAAUC,EAAMC,GAErB,MAAMiC,EAEPC,EAAIpB,CACN,MACEoB,EAAIlC,EAEL,IAAMoC,EAAYF,GACjB,MAAM,IAAI5B,UAAWC,EAAQ,WAAY2B,IAU1C,YARqB,IAAhBnC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ6B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIN,UAAWC,EAAQ,WAAYK,IAE1C,IAAMwB,EAAYrB,GACjB,MAAM,IAAIT,UAAWC,EAAQ,WAAYQ,IAE1C,OAAOP,EAAOI,EAAY2B,EAASxC,EAAMmC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,EACZ,GACD,CACF,CC1EA,SAASyB,EAAkB1B,EAAY2B,EAASvC,EAASc,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAShC,EAATgC,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAShC,EAASc,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,EAC/C,CClBA0B,EAAAC,EAAA,UAAAV"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 1cd0d47..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,164 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var validate = require( './validate.js' ); -var limit = require( './limit.js' ); - - -// MAIN // - -/** -* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} last argument must be a function -* @returns {Function} function which invokes the provided function once for each element in a collection -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error, data ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var opts = { -* 'series': false -* }; -* -* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: -* var reduceRightAsync = factory( opts, read ); -* -* // Create a collection over which to iterate: -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* // Define a callback which handles errors: -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* // Run `read` for each element in `files`: -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, done ); -*/ -function factory( options, fcn ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = fcn; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '1RZ3q,JV', f ) ); - } - if ( opts.series === void 0 && opts.limit === void 0 ) { - opts.series = true; - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return reduceRightAsync; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * @private - * @param {Collection} collection - input collection - * @param {*} initial - initial value - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be a collection - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function reduceRightAsync( collection, initial, done ) { - if ( !isCollection( collection ) ) { - throw new TypeError( format( '1RZAh,O3', collection ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '1RZ3q,JV', done ) ); - } - return limit( collection, initial, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {*} [acc] - accumulated value - * @returns {void} - */ - function clbk( error, acc ) { - if ( error ) { - return done( error ); - } - done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ae657ff..0000000 --- a/lib/index.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* @module @stdlib/utils-async-reduce-right -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' ); -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/limit.js b/lib/limit.js deleted file mode 100644 index cdb60af..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); - - -// VARIABLES // - -var debug = logger( 'reduce-right-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each element in a collection, limiting the number of concurrently pending functions and iterating from right to left. -* -* @private -* @param {Collection} collection - input collection -* @param {*} acc - initial value -* @param {Options} opts - function options -* @param {*} [opts.thisArg] - execution context -* @param {PositiveInteger} [opts.limit] - maximum number of pending function invocations -* @param {Function} fcn - function to invoke -* @param {Callback} done - function to invoke upon completion or upon encountering an error -* @returns {void} -*/ -function limit( collection, acc, opts, fcn, done ) { - var count; - var flg; - var lim; - var len; - var idx; - var i; - - len = collection.length; - debug( 'Collection length: %d', len ); - - if ( len === 0 ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - count = 0; - idx = len; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all collection elements... - if ( idx > 0 ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next element in a collection. - * - * @private - */ - function next() { - idx -= 1; - debug( 'Collection element %d: %s.', idx, JSON.stringify( collection[ idx ] ) ); - if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], cb ); - } else if ( fcn.length === 4 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, cb ); - } else { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len - } - /** - * Callback invoked once a provided function finishes processing a collection element. - * - * @private - * @param {*} [error] - error - * @param {*} [result] - accumulation result - * @returns {void} - */ - function cb( error, result ) { - if ( flg ) { - // Prevent further processing of collection elements: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Accumulator: %s', JSON.stringify( result ) ); - acc = result; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next collection element. - * - * @private - * @param {*} [error] - error - * @returns {void} - */ - function clbk( error ) { - if ( error ) { - debug( 'Encountered an error: %s', error.message ); - return done( error ); - } - count += 1; - debug( 'Processed %d of %d collection elements.', count, len ); - if ( idx > 0 ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index c8b0d0f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param {Collection} collection - input collection -* @param {*} initial - initial value -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} second-to-last argument must be a function -* @throws {TypeError} last argument must be a function -* @returns {void} -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -function reduceRightAsync( collection, initial, options, fcn, done ) { - if ( arguments.length < 5 ) { - return factory( options )( collection, initial, fcn ); - } - factory( options, fcn )( collection, initial, done ); -} - - -// EXPORTS // - -module.exports = reduceRightAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index c90c17f..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @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 -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'thisArg': {}, -* 'series': false, -* 'limit': 10 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '1RZ2V,FD', options ) ); - } - if ( hasOwnProp( options, 'thisArg' ) ) { - opts.thisArg = options.thisArg; - } - if ( hasOwnProp( options, 'series' ) ) { - opts.series = options.series; - if ( !isBoolean( opts.series ) ) { - return new TypeError( format( '1RZ2o,GE', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '1RZ3P,Fv', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 3b70e02..d4f9525 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,43 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-boolean": "^0.1.1", - "@stdlib/assert-is-collection": "^0.1.0", - "@stdlib/assert-is-function": "^0.1.1", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/assert-is-positive-integer": "^0.1.0", - "@stdlib/constants-float64-pinf": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.2.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/bench": "^0.2.0", - "@stdlib/constants-float64-eps": "^0.1.1", - "@stdlib/fs-read-file": "^0.1.1", - "@stdlib/utils-noop": "^0.1.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..c141cc6 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 8244931..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1095 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( {}, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, next ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - factory( opts, next ); - }; - } -}); - -tape( 'the function returns a function (no options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided a collection (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a collection (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (1 argument)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (2 arguments)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with five arguments', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn() { - var value; - var next; - var acc; - var k; - - acc = arguments[ 0 ]; - value = arguments[ 1 ]; - k = arguments[ 2 ]; - next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( k, i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the returned function supports processing collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements concurrently', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 100, 250, 300 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements sequentially (limit = 1)', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of collection elements which are processed at any one time', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 250, 300, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 250, 100, 300 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var reduceRightAsync; - var arr; - - reduceRightAsync = factory( fcn ); - arr = []; - - reduceRightAsync( arr, 0, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var reduceRightAsync; - var obj; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = []; - obj = {}; - reduceRightAsync( arr, obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - i = 0; - - reduceRightAsync( arr, {}, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, acc ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the returned function does not skip empty elements', function test( t ) { - var reduceRightAsync; - var expected; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index f273a40..0000000 --- a/test/test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof reduceRightAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 1893240..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1035 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a collection', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (no options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, next, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, 0 ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - reduceRightAsync( [ 1, 2, 3 ], 0, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (1 argument)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (2 arguments)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with five arguments', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn() { - var next; - var acc; - var v; - - next = arguments[ 4 ]; - acc = arguments[ 0 ]; - v = arguments[ 1 ]; - - i -= 1; - j += 1; - - t.strictEqual( v, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, v ); - - function onTimeout() { - acc.sum += v; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'by default, the function processes collection elements sequentially', function test( t ) { - var values; - var count; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements concurrently', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 100, 250, 300 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': true - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially (limit = 1)', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var arr; - var ctx; - - arr = [ 3, 2, 1 ]; - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 3, 2, 1 ]; - opts = { - 'series': true - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 250, 100, 300 ]; - opts = { - 'limit': 2 - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var arr = []; - reduceRightAsync( arr, 0, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var arr = []; - var obj = {}; - - reduceRightAsync( arr, obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - arr = [ 3, 2, 1 ]; - i = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, value ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the function does not skip empty elements', function test( t ) { - var expected; - var arr; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, fcn, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 7660838..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,181 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `limit` option which is not a positive integer', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - -5, - 0, - 3.14, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'limit': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `series` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'series': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function accepts any value for the `thisArg` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'thisArg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err, null, 'returns null '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'thisArg': {}, - 'series': false, - 'limit': 10 - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From 517522d10274d063ca529be6d0c0e155a2908daf Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Dec 2023 06:57:42 +0000 Subject: [PATCH 085/147] Transform error messages --- lib/factory.js | 8 ++++---- lib/validate.js | 8 ++++---- package.json | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 1125052..1cd0d47 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -22,7 +22,7 @@ var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var PINF = require( '@stdlib/constants-float64-pinf' ); var validate = require( './validate.js' ); var limit = require( './limit.js' ); @@ -109,7 +109,7 @@ function factory( options, fcn ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '1RZ3q,JV', f ) ); } if ( opts.series === void 0 && opts.limit === void 0 ) { opts.series = true; @@ -134,10 +134,10 @@ function factory( options, fcn ) { */ function reduceRightAsync( collection, initial, done ) { if ( !isCollection( collection ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a collection. Value: `%s`.', collection ) ); + throw new TypeError( format( '1RZAh,O3', collection ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '1RZ3q,JV', done ) ); } return limit( collection, initial, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index 9ba927e..c90c17f 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,7 +54,7 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '1RZ2V,FD', options ) ); } if ( hasOwnProp( options, 'thisArg' ) ) { opts.thisArg = options.thisArg; @@ -62,13 +62,13 @@ function validate( opts, options ) { if ( hasOwnProp( options, 'series' ) ) { opts.series = options.series; if ( !isBoolean( opts.series ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'series', opts.series ) ); + return new TypeError( format( '1RZ2o,GE', 'series', opts.series ) ); } } if ( hasOwnProp( options, 'limit' ) ) { opts.limit = options.limit; if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'limit', opts.limit ) ); + return new TypeError( format( '1RZ3P,Fv', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index ac69012..7931142 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-plain-object": "^0.1.1", "@stdlib/assert-is-positive-integer": "^0.1.0", "@stdlib/constants-float64-pinf": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1", "debug": "^2.6.9" From 091f91bd14c971db3e0980b794fc5ebde9b1b066 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Dec 2023 01:55:24 +0000 Subject: [PATCH 086/147] Remove files --- index.d.ts | 410 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6592 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 816cbe3..0000000 --- a/index.d.ts +++ /dev/null @@ -1,410 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Execution context. - */ - thisArg?: ThisParameterType>; - - /** - * The maximum number of pending invocations at any one time. - */ - limit?: number; - - /** - * Boolean indicating whether to sequentially invoke the reducer function for each `collection` element. If `true`, the function sets `options.limit=1`. Default: true. - */ - series?: boolean; -} - -/** -* Callback function. -*/ -type Nullary = () => void; - -/** -* Callback function. -* -* @param error - encountered error or null -*/ -type Unary = ( error: Error | null ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Binary = ( error: Error | null, accumulator: U ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param next - a callback to be invoked after processing a collection `value` -*/ -type TernaryReducer = ( this: V, accumulator: U, value: T, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuaternaryReducer = ( this: V, accumulator: U, value: T, index: number, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuinaryReducer = ( this: V, accumulator: U, value: T, index: number, collection: Collection, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type Reducer = TernaryReducer | QuaternaryReducer | QuinaryReducer; - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result. -* -* @param collection - input collection -* @param initial - initial value -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( collection: Collection, initial: U, done: Callback ) => void; - -/** -* Interface for `reduceRightAsync`. -*/ -interface ReduceRightAsync { - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, {}, read, done ); - */ - ( collection: Collection, initial: U, options: Options, reducer: Reducer, done: Callback ): void; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, read, done ); - */ - ( collection: Collection, initial: U, reducer: Reducer, done: Callback ): void; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @throws must provide valid options - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var opts = { - * 'series': false - * }; - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( opts, read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( options: Options, reducer: Reducer ): FactoryFunction; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param reducer - function to invoke for each element in a collection - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( reducer: Reducer ): FactoryFunction; -} - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param collection - input collection -* @param initial - initial value -* @param options - function options -* @param options.thisArg - execution context -* @param options.limit - maximum number of pending invocations at any one time -* @param 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 (default: true) -* @param reducer - function to invoke for each element in a collection -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( `@stdlib/fs/read-file` ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -declare var reduceRightAsync: ReduceRightAsync; - - -// EXPORTS // - -export = reduceRightAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 2c6cb00..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import{isPrimitive as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.1.0-esm/index.mjs";function m(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("1RZ2o,GE","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!d(e.limit))?new TypeError(r("1RZ3P,Fv","limit",e.limit)):null):new TypeError(r("1RZ2V,FD",t))}function c(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){if(this instanceof e){var i=[null];i.push.apply(i,arguments);var r=Function.bind.apply(t,i);return new r}return t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var f=c(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function p(e,t,i,r,s){var n,o,l,d,m,c;if(d=e.length,f("Collection length: %d",d),0===d)return f("Finished processing a collection."),s(null,t);for(l=d0&&p();function p(){function s(e,i){if(!o){if(e)return o=!0,u(e);f("Accumulator: %s",JSON.stringify(i)),t=i,u()}}f("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function u(e){return e?(f("Encountered an error: %s",e.message),s(e)):(f("Processed %d of %d collection elements.",n+=1,d),m>0?p():n===d?(f("Finished processing a collection."),s(null,t)):void 0)}}function u(e,n){var o,l,d;if(o={},arguments.length>1){if(l=m(o,e))throw l;d=n}else d=e;if(!t(d))throw new TypeError(r("1RZ3q,JV",d));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=s),c;function c(e,s,n){if(!i(e))throw new TypeError(r("1RZAh,O3",e));if(!t(n))throw new TypeError(r("1RZ3q,JV",n));return p(e,s,o,d,(function(e,t){if(e)return n(e);n(null,t)}))}}function a(e,t,i,r,s){if(arguments.length<5)return u(i)(e,t,r);u(i,r)(e,t,s)}e(a,"factory",u);export{a as default,u as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 655de94..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '1RZ2V,FD', 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( '1RZ2o,GE', '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( '1RZ3P,Fv', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RZ3q,JV', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '1RZAh,O3', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RZ3q,JV', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","logger","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly","main"],"mappings":";;w5BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,WAAY,SAAUR,EAAKK,SAGtDF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,WAAY,QAASR,EAAKS,QAGnD,MAjBC,IAAIF,UAAWC,EAAQ,WAAYP,GAkB5C,8eC/CIU,uDAAQC,CAAQ,4BAkBpB,SAASH,EAAOI,EAAYC,EAAKd,EAAMe,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMP,EAAWU,OACjBZ,EAAO,wBAAyBS,GAEnB,IAARA,EAEJ,OADAT,EAAO,qCACAK,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAEZE,EAAO,wBAAyBQ,GAChCR,EAAO,0BAA2BI,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdf,EAAO,kBAAmBkB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,GAPC,CAQD,CA5BDjB,EAAO,6BADPU,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJf,EAAO,2BAA4Be,EAAMM,SAClChB,EAAMU,KAGdf,EAAO,0CADPM,GAAS,EACgDG,GACpDC,EAAM,EACHG,IAEHP,IAAUG,GACdT,EAAO,qCACAK,EAAM,KAAMF,SAFpB,EAIA,CACF,CCzCA,SAASmB,EAAShC,EAASc,GAC1B,IAAIf,EACAkC,EACAC,EAGJ,GADAnC,EAAO,CAAA,EACFoC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMnC,EAAUC,EAAMC,GAErB,MAAMiC,EAEPC,EAAIpB,CACN,MACEoB,EAAIlC,EAEL,IAAMoC,EAAYF,GACjB,MAAM,IAAI5B,UAAWC,EAAQ,WAAY2B,IAU1C,YARqB,IAAhBnC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ6B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIN,UAAWC,EAAQ,WAAYK,IAE1C,IAAMwB,EAAYrB,GACjB,MAAM,IAAIT,UAAWC,EAAQ,WAAYQ,IAE1C,OAAOP,EAAOI,EAAY2B,EAASxC,EAAMmC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,EACZ,GACD,CACF,CC1EA,SAASyB,EAAkB1B,EAAY2B,EAASvC,EAASc,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAShC,EAATgC,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAShC,EAASc,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,EAC/C,CClBA0B,EAAAC,EAAA,UAAAV"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index c141cc6..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 1af2894012fe3b8074965a1ff9be86b576ba9e7d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Dec 2023 01:56:01 +0000 Subject: [PATCH 087/147] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 47 +- benchmark/benchmark.factory.js | 73 - benchmark/benchmark.js | 160 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 224 - docs/types/test.ts | 166 - examples/index.js | 55 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 164 - lib/index.js | 77 - lib/limit.js | 142 - lib/main.js | 95 - lib/validate.js | 80 - package.json | 64 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 1095 ---- test/test.js | 38 - test/test.main.js | 1035 ---- test/test.validate.js | 181 - 49 files changed, 6208 insertions(+), 6942 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/limit.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 2be80ab..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-12-01T03:06:33.001Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1e08946..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 5358060..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 372758f..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '37 1 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -458,7 +457,7 @@ reduceRightAsync( files, acc, read, done ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -526,11 +525,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right +[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right/tree/esm -[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce +[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/tree/esm diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 46d8b83..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var reduceRightAsync; - var arr; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - reduceRightAsync = factory( onItem ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - var acc; - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 6ad0714..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var reduceRightAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=false', function benchmark( b ) { - var opts; - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'series': false - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var arr; - var len; - var acc; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'limit': 3 - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index acfc6d6..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right" -%% click B href "https://github.com/stdlib-js/utils-async-reduce-right/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-reduce-right/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-reduce-right/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-reduce-right/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right -[production-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 47a072e..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import reduceRightAsync from '../docs/types/index'; -export = reduceRightAsync; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 530ca4d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var c=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var x=c(function(U,O){ -var R=require('@stdlib/assert-is-plain-object/dist'),h=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,k=require('@stdlib/assert-is-positive-integer/dist').isPrimitive,d=require('@stdlib/error-tools-fmtprodmsg/dist');function I(e,r){return R(r)?(h(r,"thisArg")&&(e.thisArg=r.thisArg),h(r,"series")&&(e.series=r.series,!j(e.series))?new TypeError(d('1RZ2o',"series",e.series)):h(r,"limit")&&(e.limit=r.limit,!k(e.limit))?new TypeError(d('1RZ3P',"limit",e.limit)):null):new TypeError(d('1RZ2V',r));}O.exports=I -});var P=c(function(W,E){ -var J=require("debug"),a=J("reduce-right-async:limit");function L(e,r,i,t,s){var f,m,v,n,u,g;if(n=e.length,a("Collection length: %d",n),n===0)return a("Finished processing a collection."),s(null,r);for(n0&&o();function o(){u-=1,a("Collection element %d: %s.",u,JSON.stringify(e[u])),t.length===3?t.call(i.thisArg,r,e[u],l):t.length===4?t.call(i.thisArg,r,e[u],u,l):t.call(i.thisArg,r,e[u],u,e,l);function l(w,A){if(!m){if(w)return m=!0,b(w);a("Accumulator: %s",JSON.stringify(A)),r=A,b()}}}function b(l){if(l)return a("Encountered an error: %s",l.message),s(l);if(f+=1,a("Processed %d of %d collection elements.",f,n),u>0)return o();if(f===n)return a("Finished processing a collection."),s(null,r)}}E.exports=L -});var q=c(function(X,F){ -var T=require('@stdlib/assert-is-function/dist'),S=require('@stdlib/assert-is-collection/dist'),y=require('@stdlib/error-tools-fmtprodmsg/dist'),B=require('@stdlib/constants-float64-pinf/dist'),z=x(),D=P();function G(e,r){var i,t,s;if(i={},arguments.length>1){if(t=z(i,e),t)throw t;s=r}else s=e;if(!T(s))throw new TypeError(y('1RZ3q',s));return i.series===void 0&&i.limit===void 0&&(i.series=!0),i.series?i.limit=1:i.limit||(i.limit=B),f;function f(m,v,n){if(!S(m))throw new TypeError(y('1RZAh',m));if(!T(n))throw new TypeError(y('1RZ3q',n));return D(m,v,i,s,u);function u(g,o){if(g)return n(g);n(null,o)}}}F.exports=G -});var N=c(function(Y,C){ -var p=q();function H(e,r,i,t,s){if(arguments.length<5)return p(i)(e,r,t);p(i,t)(e,r,s)}C.exports=H -});var K=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),V=N(),M=q();K(V,"factory",M);module.exports=V; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index acb9d67..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/limit.js", "../lib/factory.js", "../lib/main.js", "../lib/index.js"], - "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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\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 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 to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\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 === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, 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 ( !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, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\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* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nmodule.exports = reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' );\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, 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"], - "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,0BAA2B,EAkB/C,SAASE,EAAOC,EAAYC,EAAKC,EAAMC,EAAKC,EAAO,CAClD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMR,EAAW,OACjBF,EAAO,wBAAyBU,CAAI,EAE/BA,IAAQ,EACZ,OAAAV,EAAO,mCAAoC,EACpCM,EAAM,KAAMH,CAAI,EAYxB,IAVKO,EAAMN,EAAK,MACfK,EAAMC,EAEND,EAAML,EAAK,MAEZJ,EAAO,wBAAyBS,CAAI,EACpCT,EAAO,0BAA2BK,EAAI,MAAO,EAE7CE,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVE,EAAK,EAQP,SAASA,GAAO,CACfF,GAAO,EACPX,EAAO,6BAA8BW,EAAK,KAAK,UAAWT,EAAYS,CAAI,CAAE,CAAE,EACzEN,EAAI,SAAW,EACnBA,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGG,CAAG,EACxCT,EAAI,SAAW,EAC1BA,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGA,EAAKG,CAAG,EAExDT,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGA,EAAKT,EAAYY,CAAG,EAUrE,SAASA,EAAIC,EAAOC,EAAS,CAC5B,GAAK,CAAAR,EAIL,IAAKO,EACJ,OAAAP,EAAM,GACCS,EAAMF,CAAM,EAEpBf,EAAO,kBAAmB,KAAK,UAAWgB,CAAO,CAAE,EACnDb,EAAMa,EACNC,EAAK,EACN,CACD,CASA,SAASA,EAAMF,EAAQ,CACtB,GAAKA,EACJ,OAAAf,EAAO,2BAA4Be,EAAM,OAAQ,EAC1CT,EAAMS,CAAM,EAIpB,GAFAR,GAAS,EACTP,EAAO,0CAA2CO,EAAOG,CAAI,EACxDC,EAAM,EACV,OAAOE,EAAK,EAEb,GAAKN,IAAUG,EACd,OAAAV,EAAO,mCAAoC,EACpCM,EAAM,KAAMH,CAAI,CAEzB,CACD,CAKAL,EAAO,QAAUG,IC7IjB,IAAAiB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,gCAAiC,EACjDC,EAAW,IACXC,EAAQ,IAoEZ,SAASC,EAASC,EAASC,EAAM,CAChC,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,CAACP,EAAYW,CAAE,EACnB,MAAM,IAAI,UAAWT,EAAQ,mEAAoES,CAAE,CAAE,EAEtG,OAAKF,EAAK,SAAW,QAAUA,EAAK,QAAU,SAC7CA,EAAK,OAAS,IAEVA,EAAK,OACTA,EAAK,MAAQ,EACDA,EAAK,QACjBA,EAAK,MAAQN,GAEPS,EAaP,SAASA,EAAkBC,EAAYC,EAASC,EAAO,CACtD,GAAK,CAACd,EAAcY,CAAW,EAC9B,MAAM,IAAI,UAAWX,EAAQ,sEAAuEW,CAAW,CAAE,EAElH,GAAK,CAACb,EAAYe,CAAK,EACtB,MAAM,IAAI,UAAWb,EAAQ,mEAAoEa,CAAK,CAAE,EAEzG,OAAOV,EAAOQ,EAAYC,EAASL,EAAME,EAAGK,CAAK,EAUjD,SAASA,EAAMC,EAAOC,EAAM,CAC3B,GAAKD,EACJ,OAAOF,EAAME,CAAM,EAEpBF,EAAM,KAAMG,CAAI,CACjB,CACD,CACD,CAKAnB,EAAO,QAAUO,ICnKjB,IAAAa,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,IA8Dd,SAASC,EAAkBC,EAAYC,EAASC,EAASC,EAAKC,EAAO,CACpE,GAAK,UAAU,OAAS,EACvB,OAAON,EAASI,CAAQ,EAAGF,EAAYC,EAASE,CAAI,EAErDL,EAASI,EAASC,CAAI,EAAGH,EAAYC,EAASG,CAAK,CACpD,CAKAP,EAAO,QAAUE,IC9BjB,IAAIM,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "isPositiveInteger", "format", "validate", "opts", "options", "require_limit", "__commonJSMin", "exports", "module", "logger", "debug", "limit", "collection", "acc", "opts", "fcn", "done", "count", "flg", "lim", "len", "idx", "i", "next", "cb", "error", "result", "clbk", "require_factory", "__commonJSMin", "exports", "module", "isFunction", "isCollection", "format", "PINF", "validate", "limit", "factory", "options", "fcn", "opts", "err", "f", "reduceRightAsync", "collection", "initial", "done", "clbk", "error", "acc", "require_main", "__commonJSMin", "exports", "module", "factory", "reduceRightAsync", "collection", "initial", "options", "fcn", "done", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3f22669..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,224 +0,0 @@ - -{{alias}}( collection, initial, [options,] reducer, done ) - Applies a function against an accumulator and each element in a collection - and returns the accumulated result, iterating from right to left. - - When invoked, `reducer` is provided a maximum of five arguments: - - - `accumulator`: accumulated value - - `value`: collection value - - `index`: collection index - - `collection`: the input collection - - `next`: a callback to be invoked after processing a collection `value` - - The actual number of provided arguments depends on function length. If - `reducer` accepts three arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `next` - - If `reducer` accepts four arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `index` - - `next` - - For every other `reducer` signature, `reducer` is provided all five - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `accumulator`: accumulated value - - If a provided function calls the `next` callback with a truthy `error` - argument, the function suspends execution and immediately calls the `done` - callback for subsequent `error` handling. - - Execution is *not* guaranteed to be asynchronous. To guarantee asynchrony, - 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`). - - The function does not support dynamic collection resizing. - - If provided an empty collection, the function invokes the `done` callback - with the `initial` value as the second argument. - - The function does not skip `undefined` elements. - - When processing collection elements concurrently, *beware* of race - conditions when updating an accumulator. This is especially true when an - accumulator is a primitive (e.g., a number). In general, prefer object - accumulators. - - Parameters - ---------- - collection: Array|TypedArray|Object - Input collection over which to iterate. If provided an object, the - object must be array-like (excluding strings and functions). - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - reducer: Function - The function to invoke for each element in a collection. - - done: Function - A callback invoked either upon processing all collection elements or - upon encountering an error. - - Examples - -------- - // Basic usage: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, fcn, done ) - 3000 - 2500 - 1000 - 6500 - - // Limit number of concurrent invocations: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'limit': 2 }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 2500 - 3000 - 1000 - 6500 - - // Process concurrently: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'series': false }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 1000 - 2500 - 3000 - 6500 - - -{{alias}}.factory( [options,] fcn ) - Returns a function which applies a function against an accumulator and each - element in a collection and returns the accumulated result, iterating from - right to left. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - fcn: Function - The function to invoke for each element in a collection. - - Returns - ------- - out: Function - A function which invokes a function for each element in a collection. - - Examples - -------- - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > var opts = { 'series': false }; - > var f = {{alias}}.factory( opts, fcn ); - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > f( arr, acc, done ) - 1000 - 2500 - 3000 - 6500 - > acc = { 'sum': 0 }; - > arr = [ 1000, 1500, 2000 ]; - > f( arr, acc, done ) - 1000 - 1500 - 2000 - 4500 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0455864..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,166 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unsafe-assignment */ - -import reduceRightAsync = require( './index' ); - -const reducer = ( acc: any, value: number, index: number, next: Function ) => { - acc.sum += value; - if ( index === void 0 ) { - throw new Error( '`index` is missing.' ); - } - next( null, acc ); -}; - -const done = ( error: Error | null, acc: any ) => { - if ( error ) { - throw error; - } - if ( acc === void 0 ) { - throw new Error( '`acc` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( 2, acc, reducer, done ); // $ExpectError - reduceRightAsync( false, acc, reducer, done ); // $ExpectError - reduceRightAsync( true, acc, reducer, done ); // $ExpectError - reduceRightAsync( {}, acc, reducer, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a predicate argument which is not a predicate function... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 2, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, false, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, true, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 'abc', done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, [], done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a done callback argument which is not a function having a supported signature... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 2 ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, false ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, true ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 'abc' ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, {} ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, [] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const acc = { 'sum': 0 }; - reduceRightAsync(); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, reducer, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - reduceRightAsync.factory( reducer ); // $ExpectType FactoryFunction - reduceRightAsync.factory( { 'series': true }, reducer ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - reduceRightAsync.factory( [], reducer ); // $ExpectError - reduceRightAsync.factory( 123, reducer ); // $ExpectError - reduceRightAsync.factory( 'abc', reducer ); // $ExpectError - reduceRightAsync.factory( false, reducer ); // $ExpectError - reduceRightAsync.factory( true, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not a predicate function... -{ - reduceRightAsync.factory( {} ); // $ExpectError - reduceRightAsync.factory( true ); // $ExpectError - reduceRightAsync.factory( false ); // $ExpectError - reduceRightAsync.factory( {}, 123 ); // $ExpectError - reduceRightAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1( 12, acc, done ); // $ExpectError - fcn1( true, acc, done ); // $ExpectError - fcn1( false, acc, done ); // $ExpectError - fcn1( {}, acc, done ); // $ExpectError - - fcn1( [ 3000, 2500, 1000 ], acc, 12 ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, true ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, false ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, '5' ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, {} ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, [] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1(); // $ExpectError - fcn1( [ 3000, 2500, 1000 ] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - reduceRightAsync.factory( { 'limit': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': true }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': false }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - reduceRightAsync.factory( { 'series': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': 12 }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - reduceRightAsync.factory(); // $ExpectError - reduceRightAsync.factory( {}, reducer, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index dd64345..0000000 --- a/examples/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var resolve = require( 'path' ).resolve; -var readFile = require( '@stdlib/fs-read-file' ); -var reduceRightAsync = require( './../lib' ); - -var files = [ - resolve( __dirname, '..', 'package.json' ), - resolve( __dirname, '..', 'README.md' ) -]; - -function done( error, acc ) { - if ( error ) { - throw error; - } - console.log( acc.count ); -} - -function read( acc, file, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( file, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( null, acc ); - } - acc.count += 1; - next( null, acc ); - } -} - -var acc = { - 'count': 0 -}; -reduceRightAsync( files, acc, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 16e0539..816cbe3 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..2c6cb00 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import{isPrimitive as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.1.0-esm/index.mjs";function m(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("1RZ2o,GE","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!d(e.limit))?new TypeError(r("1RZ3P,Fv","limit",e.limit)):null):new TypeError(r("1RZ2V,FD",t))}function c(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){if(this instanceof e){var i=[null];i.push.apply(i,arguments);var r=Function.bind.apply(t,i);return new r}return t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var f=c(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function p(e,t,i,r,s){var n,o,l,d,m,c;if(d=e.length,f("Collection length: %d",d),0===d)return f("Finished processing a collection."),s(null,t);for(l=d0&&p();function p(){function s(e,i){if(!o){if(e)return o=!0,u(e);f("Accumulator: %s",JSON.stringify(i)),t=i,u()}}f("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function u(e){return e?(f("Encountered an error: %s",e.message),s(e)):(f("Processed %d of %d collection elements.",n+=1,d),m>0?p():n===d?(f("Finished processing a collection."),s(null,t)):void 0)}}function u(e,n){var o,l,d;if(o={},arguments.length>1){if(l=m(o,e))throw l;d=n}else d=e;if(!t(d))throw new TypeError(r("1RZ3q,JV",d));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=s),c;function c(e,s,n){if(!i(e))throw new TypeError(r("1RZAh,O3",e));if(!t(n))throw new TypeError(r("1RZ3q,JV",n));return p(e,s,o,d,(function(e,t){if(e)return n(e);n(null,t)}))}}function a(e,t,i,r,s){if(arguments.length<5)return u(i)(e,t,r);u(i,r)(e,t,s)}e(a,"factory",u);export{a as default,u as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..655de94 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '1RZ2V,FD', 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( '1RZ2o,GE', '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( '1RZ3P,Fv', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RZ3q,JV', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '1RZAh,O3', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RZ3q,JV', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","logger","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly","main"],"mappings":";;w5BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,WAAY,SAAUR,EAAKK,SAGtDF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,WAAY,QAASR,EAAKS,QAGnD,MAjBC,IAAIF,UAAWC,EAAQ,WAAYP,GAkB5C,8eC/CIU,uDAAQC,CAAQ,4BAkBpB,SAASH,EAAOI,EAAYC,EAAKd,EAAMe,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMP,EAAWU,OACjBZ,EAAO,wBAAyBS,GAEnB,IAARA,EAEJ,OADAT,EAAO,qCACAK,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAEZE,EAAO,wBAAyBQ,GAChCR,EAAO,0BAA2BI,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdf,EAAO,kBAAmBkB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,GAPC,CAQD,CA5BDjB,EAAO,6BADPU,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJf,EAAO,2BAA4Be,EAAMM,SAClChB,EAAMU,KAGdf,EAAO,0CADPM,GAAS,EACgDG,GACpDC,EAAM,EACHG,IAEHP,IAAUG,GACdT,EAAO,qCACAK,EAAM,KAAMF,SAFpB,EAIA,CACF,CCzCA,SAASmB,EAAShC,EAASc,GAC1B,IAAIf,EACAkC,EACAC,EAGJ,GADAnC,EAAO,CAAA,EACFoC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMnC,EAAUC,EAAMC,GAErB,MAAMiC,EAEPC,EAAIpB,CACN,MACEoB,EAAIlC,EAEL,IAAMoC,EAAYF,GACjB,MAAM,IAAI5B,UAAWC,EAAQ,WAAY2B,IAU1C,YARqB,IAAhBnC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ6B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIN,UAAWC,EAAQ,WAAYK,IAE1C,IAAMwB,EAAYrB,GACjB,MAAM,IAAIT,UAAWC,EAAQ,WAAYQ,IAE1C,OAAOP,EAAOI,EAAY2B,EAASxC,EAAMmC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,EACZ,GACD,CACF,CC1EA,SAASyB,EAAkB1B,EAAY2B,EAASvC,EAASc,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAShC,EAATgC,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAShC,EAASc,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,EAC/C,CClBA0B,EAAAC,EAAA,UAAAV"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 1cd0d47..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,164 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var validate = require( './validate.js' ); -var limit = require( './limit.js' ); - - -// MAIN // - -/** -* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} last argument must be a function -* @returns {Function} function which invokes the provided function once for each element in a collection -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error, data ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var opts = { -* 'series': false -* }; -* -* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: -* var reduceRightAsync = factory( opts, read ); -* -* // Create a collection over which to iterate: -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* // Define a callback which handles errors: -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* // Run `read` for each element in `files`: -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, done ); -*/ -function factory( options, fcn ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = fcn; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '1RZ3q,JV', f ) ); - } - if ( opts.series === void 0 && opts.limit === void 0 ) { - opts.series = true; - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return reduceRightAsync; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * @private - * @param {Collection} collection - input collection - * @param {*} initial - initial value - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be a collection - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function reduceRightAsync( collection, initial, done ) { - if ( !isCollection( collection ) ) { - throw new TypeError( format( '1RZAh,O3', collection ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '1RZ3q,JV', done ) ); - } - return limit( collection, initial, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {*} [acc] - accumulated value - * @returns {void} - */ - function clbk( error, acc ) { - if ( error ) { - return done( error ); - } - done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ae657ff..0000000 --- a/lib/index.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* @module @stdlib/utils-async-reduce-right -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' ); -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/limit.js b/lib/limit.js deleted file mode 100644 index cdb60af..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); - - -// VARIABLES // - -var debug = logger( 'reduce-right-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each element in a collection, limiting the number of concurrently pending functions and iterating from right to left. -* -* @private -* @param {Collection} collection - input collection -* @param {*} acc - initial value -* @param {Options} opts - function options -* @param {*} [opts.thisArg] - execution context -* @param {PositiveInteger} [opts.limit] - maximum number of pending function invocations -* @param {Function} fcn - function to invoke -* @param {Callback} done - function to invoke upon completion or upon encountering an error -* @returns {void} -*/ -function limit( collection, acc, opts, fcn, done ) { - var count; - var flg; - var lim; - var len; - var idx; - var i; - - len = collection.length; - debug( 'Collection length: %d', len ); - - if ( len === 0 ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - count = 0; - idx = len; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all collection elements... - if ( idx > 0 ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next element in a collection. - * - * @private - */ - function next() { - idx -= 1; - debug( 'Collection element %d: %s.', idx, JSON.stringify( collection[ idx ] ) ); - if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], cb ); - } else if ( fcn.length === 4 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, cb ); - } else { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len - } - /** - * Callback invoked once a provided function finishes processing a collection element. - * - * @private - * @param {*} [error] - error - * @param {*} [result] - accumulation result - * @returns {void} - */ - function cb( error, result ) { - if ( flg ) { - // Prevent further processing of collection elements: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Accumulator: %s', JSON.stringify( result ) ); - acc = result; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next collection element. - * - * @private - * @param {*} [error] - error - * @returns {void} - */ - function clbk( error ) { - if ( error ) { - debug( 'Encountered an error: %s', error.message ); - return done( error ); - } - count += 1; - debug( 'Processed %d of %d collection elements.', count, len ); - if ( idx > 0 ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index c8b0d0f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param {Collection} collection - input collection -* @param {*} initial - initial value -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} second-to-last argument must be a function -* @throws {TypeError} last argument must be a function -* @returns {void} -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -function reduceRightAsync( collection, initial, options, fcn, done ) { - if ( arguments.length < 5 ) { - return factory( options )( collection, initial, fcn ); - } - factory( options, fcn )( collection, initial, done ); -} - - -// EXPORTS // - -module.exports = reduceRightAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index c90c17f..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @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 -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'thisArg': {}, -* 'series': false, -* 'limit': 10 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '1RZ2V,FD', options ) ); - } - if ( hasOwnProp( options, 'thisArg' ) ) { - opts.thisArg = options.thisArg; - } - if ( hasOwnProp( options, 'series' ) ) { - opts.series = options.series; - if ( !isBoolean( opts.series ) ) { - return new TypeError( format( '1RZ2o,GE', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '1RZ3P,Fv', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 7931142..d4f9525 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,43 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-boolean": "^0.1.1", - "@stdlib/assert-is-collection": "^0.1.0", - "@stdlib/assert-is-function": "^0.1.1", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/assert-is-positive-integer": "^0.1.0", - "@stdlib/constants-float64-pinf": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.2.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/bench": "^0.2.1", - "@stdlib/constants-float64-eps": "^0.1.1", - "@stdlib/fs-read-file": "^0.1.1", - "@stdlib/utils-noop": "^0.1.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..956fe17 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 8244931..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1095 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( {}, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, next ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - factory( opts, next ); - }; - } -}); - -tape( 'the function returns a function (no options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided a collection (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a collection (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (1 argument)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (2 arguments)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with five arguments', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn() { - var value; - var next; - var acc; - var k; - - acc = arguments[ 0 ]; - value = arguments[ 1 ]; - k = arguments[ 2 ]; - next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( k, i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the returned function supports processing collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements concurrently', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 100, 250, 300 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements sequentially (limit = 1)', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of collection elements which are processed at any one time', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 250, 300, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 250, 100, 300 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var reduceRightAsync; - var arr; - - reduceRightAsync = factory( fcn ); - arr = []; - - reduceRightAsync( arr, 0, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var reduceRightAsync; - var obj; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = []; - obj = {}; - reduceRightAsync( arr, obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - i = 0; - - reduceRightAsync( arr, {}, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, acc ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the returned function does not skip empty elements', function test( t ) { - var reduceRightAsync; - var expected; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index f273a40..0000000 --- a/test/test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof reduceRightAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 1893240..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1035 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a collection', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (no options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, next, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, 0 ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - reduceRightAsync( [ 1, 2, 3 ], 0, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (1 argument)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (2 arguments)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with five arguments', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn() { - var next; - var acc; - var v; - - next = arguments[ 4 ]; - acc = arguments[ 0 ]; - v = arguments[ 1 ]; - - i -= 1; - j += 1; - - t.strictEqual( v, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, v ); - - function onTimeout() { - acc.sum += v; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'by default, the function processes collection elements sequentially', function test( t ) { - var values; - var count; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements concurrently', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 100, 250, 300 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': true - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially (limit = 1)', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var arr; - var ctx; - - arr = [ 3, 2, 1 ]; - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 3, 2, 1 ]; - opts = { - 'series': true - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 250, 100, 300 ]; - opts = { - 'limit': 2 - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var arr = []; - reduceRightAsync( arr, 0, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var arr = []; - var obj = {}; - - reduceRightAsync( arr, obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - arr = [ 3, 2, 1 ]; - i = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, value ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the function does not skip empty elements', function test( t ) { - var expected; - var arr; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, fcn, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 7660838..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,181 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `limit` option which is not a positive integer', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - -5, - 0, - 3.14, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'limit': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `series` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'series': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function accepts any value for the `thisArg` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'thisArg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err, null, 'returns null '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'thisArg': {}, - 'series': false, - 'limit': 10 - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From 925270c89b521f9750e261e5ae0f9e3e33003e21 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 04:21:39 +0000 Subject: [PATCH 088/147] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 18a98c9..a3e4906 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-plain-object": "^0.1.1", "@stdlib/assert-is-positive-integer": "^0.1.0", "@stdlib/constants-float64-pinf": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1", "debug": "^2.6.9" From 549c4e4325b823c07b21eda240702ead540d7c67 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 10:35:56 +0000 Subject: [PATCH 089/147] Remove files --- index.d.ts | 410 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6592 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 816cbe3..0000000 --- a/index.d.ts +++ /dev/null @@ -1,410 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Execution context. - */ - thisArg?: ThisParameterType>; - - /** - * The maximum number of pending invocations at any one time. - */ - limit?: number; - - /** - * Boolean indicating whether to sequentially invoke the reducer function for each `collection` element. If `true`, the function sets `options.limit=1`. Default: true. - */ - series?: boolean; -} - -/** -* Callback function. -*/ -type Nullary = () => void; - -/** -* Callback function. -* -* @param error - encountered error or null -*/ -type Unary = ( error: Error | null ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Binary = ( error: Error | null, accumulator: U ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param next - a callback to be invoked after processing a collection `value` -*/ -type TernaryReducer = ( this: V, accumulator: U, value: T, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuaternaryReducer = ( this: V, accumulator: U, value: T, index: number, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuinaryReducer = ( this: V, accumulator: U, value: T, index: number, collection: Collection, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type Reducer = TernaryReducer | QuaternaryReducer | QuinaryReducer; - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result. -* -* @param collection - input collection -* @param initial - initial value -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( collection: Collection, initial: U, done: Callback ) => void; - -/** -* Interface for `reduceRightAsync`. -*/ -interface ReduceRightAsync { - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, {}, read, done ); - */ - ( collection: Collection, initial: U, options: Options, reducer: Reducer, done: Callback ): void; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, read, done ); - */ - ( collection: Collection, initial: U, reducer: Reducer, done: Callback ): void; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @throws must provide valid options - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var opts = { - * 'series': false - * }; - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( opts, read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( options: Options, reducer: Reducer ): FactoryFunction; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param reducer - function to invoke for each element in a collection - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( reducer: Reducer ): FactoryFunction; -} - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param collection - input collection -* @param initial - initial value -* @param options - function options -* @param options.thisArg - execution context -* @param options.limit - maximum number of pending invocations at any one time -* @param 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 (default: true) -* @param reducer - function to invoke for each element in a collection -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( `@stdlib/fs/read-file` ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -declare var reduceRightAsync: ReduceRightAsync; - - -// EXPORTS // - -export = reduceRightAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 2c6cb00..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import{isPrimitive as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.1.0-esm/index.mjs";function m(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("1RZ2o,GE","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!d(e.limit))?new TypeError(r("1RZ3P,Fv","limit",e.limit)):null):new TypeError(r("1RZ2V,FD",t))}function c(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){if(this instanceof e){var i=[null];i.push.apply(i,arguments);var r=Function.bind.apply(t,i);return new r}return t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var f=c(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function p(e,t,i,r,s){var n,o,l,d,m,c;if(d=e.length,f("Collection length: %d",d),0===d)return f("Finished processing a collection."),s(null,t);for(l=d0&&p();function p(){function s(e,i){if(!o){if(e)return o=!0,u(e);f("Accumulator: %s",JSON.stringify(i)),t=i,u()}}f("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function u(e){return e?(f("Encountered an error: %s",e.message),s(e)):(f("Processed %d of %d collection elements.",n+=1,d),m>0?p():n===d?(f("Finished processing a collection."),s(null,t)):void 0)}}function u(e,n){var o,l,d;if(o={},arguments.length>1){if(l=m(o,e))throw l;d=n}else d=e;if(!t(d))throw new TypeError(r("1RZ3q,JV",d));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=s),c;function c(e,s,n){if(!i(e))throw new TypeError(r("1RZAh,O3",e));if(!t(n))throw new TypeError(r("1RZ3q,JV",n));return p(e,s,o,d,(function(e,t){if(e)return n(e);n(null,t)}))}}function a(e,t,i,r,s){if(arguments.length<5)return u(i)(e,t,r);u(i,r)(e,t,s)}e(a,"factory",u);export{a as default,u as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 655de94..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '1RZ2V,FD', 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( '1RZ2o,GE', '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( '1RZ3P,Fv', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RZ3q,JV', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '1RZAh,O3', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RZ3q,JV', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","logger","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly","main"],"mappings":";;w5BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,WAAY,SAAUR,EAAKK,SAGtDF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,WAAY,QAASR,EAAKS,QAGnD,MAjBC,IAAIF,UAAWC,EAAQ,WAAYP,GAkB5C,8eC/CIU,uDAAQC,CAAQ,4BAkBpB,SAASH,EAAOI,EAAYC,EAAKd,EAAMe,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMP,EAAWU,OACjBZ,EAAO,wBAAyBS,GAEnB,IAARA,EAEJ,OADAT,EAAO,qCACAK,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAEZE,EAAO,wBAAyBQ,GAChCR,EAAO,0BAA2BI,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdf,EAAO,kBAAmBkB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,GAPC,CAQD,CA5BDjB,EAAO,6BADPU,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJf,EAAO,2BAA4Be,EAAMM,SAClChB,EAAMU,KAGdf,EAAO,0CADPM,GAAS,EACgDG,GACpDC,EAAM,EACHG,IAEHP,IAAUG,GACdT,EAAO,qCACAK,EAAM,KAAMF,SAFpB,EAIA,CACF,CCzCA,SAASmB,EAAShC,EAASc,GAC1B,IAAIf,EACAkC,EACAC,EAGJ,GADAnC,EAAO,CAAA,EACFoC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMnC,EAAUC,EAAMC,GAErB,MAAMiC,EAEPC,EAAIpB,CACN,MACEoB,EAAIlC,EAEL,IAAMoC,EAAYF,GACjB,MAAM,IAAI5B,UAAWC,EAAQ,WAAY2B,IAU1C,YARqB,IAAhBnC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ6B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIN,UAAWC,EAAQ,WAAYK,IAE1C,IAAMwB,EAAYrB,GACjB,MAAM,IAAIT,UAAWC,EAAQ,WAAYQ,IAE1C,OAAOP,EAAOI,EAAY2B,EAASxC,EAAMmC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,EACZ,GACD,CACF,CC1EA,SAASyB,EAAkB1B,EAAY2B,EAASvC,EAASc,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAShC,EAATgC,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAShC,EAASc,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,EAC/C,CClBA0B,EAAAC,EAAA,UAAAV"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 956fe17..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 80cd6ee4e433867c8cff4eff5523036ba0cc41c8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 10:36:11 +0000 Subject: [PATCH 090/147] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 47 +- SECURITY.md | 5 - benchmark/benchmark.factory.js | 73 - benchmark/benchmark.js | 160 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 224 - docs/types/test.ts | 166 - examples/index.js | 55 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 164 - lib/index.js | 77 - lib/limit.js | 142 - lib/main.js | 95 - lib/validate.js | 80 - package.json | 64 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 1095 ---- test/test.js | 38 - test/test.main.js | 1035 ---- test/test.validate.js | 181 - 50 files changed, 6208 insertions(+), 6948 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/limit.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 7617ba1..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-01-01T02:40:54.479Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1e08946..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 30656c4..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 5358060..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c92f5c4..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 0083051..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '37 1 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index e1e3539..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -458,7 +457,7 @@ reduceRightAsync( files, acc, read, done ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -526,11 +525,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right +[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right/tree/esm -[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce +[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index b155fd2..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var reduceRightAsync; - var arr; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - reduceRightAsync = factory( onItem ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - var acc; - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index af5c346..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var reduceRightAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=false', function benchmark( b ) { - var opts; - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'series': false - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var arr; - var len; - var acc; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'limit': 3 - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index acfc6d6..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right" -%% click B href "https://github.com/stdlib-js/utils-async-reduce-right/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-reduce-right/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-reduce-right/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-reduce-right/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right -[production-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 47a072e..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import reduceRightAsync from '../docs/types/index'; -export = reduceRightAsync; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 530ca4d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var c=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var x=c(function(U,O){ -var R=require('@stdlib/assert-is-plain-object/dist'),h=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,k=require('@stdlib/assert-is-positive-integer/dist').isPrimitive,d=require('@stdlib/error-tools-fmtprodmsg/dist');function I(e,r){return R(r)?(h(r,"thisArg")&&(e.thisArg=r.thisArg),h(r,"series")&&(e.series=r.series,!j(e.series))?new TypeError(d('1RZ2o',"series",e.series)):h(r,"limit")&&(e.limit=r.limit,!k(e.limit))?new TypeError(d('1RZ3P',"limit",e.limit)):null):new TypeError(d('1RZ2V',r));}O.exports=I -});var P=c(function(W,E){ -var J=require("debug"),a=J("reduce-right-async:limit");function L(e,r,i,t,s){var f,m,v,n,u,g;if(n=e.length,a("Collection length: %d",n),n===0)return a("Finished processing a collection."),s(null,r);for(n0&&o();function o(){u-=1,a("Collection element %d: %s.",u,JSON.stringify(e[u])),t.length===3?t.call(i.thisArg,r,e[u],l):t.length===4?t.call(i.thisArg,r,e[u],u,l):t.call(i.thisArg,r,e[u],u,e,l);function l(w,A){if(!m){if(w)return m=!0,b(w);a("Accumulator: %s",JSON.stringify(A)),r=A,b()}}}function b(l){if(l)return a("Encountered an error: %s",l.message),s(l);if(f+=1,a("Processed %d of %d collection elements.",f,n),u>0)return o();if(f===n)return a("Finished processing a collection."),s(null,r)}}E.exports=L -});var q=c(function(X,F){ -var T=require('@stdlib/assert-is-function/dist'),S=require('@stdlib/assert-is-collection/dist'),y=require('@stdlib/error-tools-fmtprodmsg/dist'),B=require('@stdlib/constants-float64-pinf/dist'),z=x(),D=P();function G(e,r){var i,t,s;if(i={},arguments.length>1){if(t=z(i,e),t)throw t;s=r}else s=e;if(!T(s))throw new TypeError(y('1RZ3q',s));return i.series===void 0&&i.limit===void 0&&(i.series=!0),i.series?i.limit=1:i.limit||(i.limit=B),f;function f(m,v,n){if(!S(m))throw new TypeError(y('1RZAh',m));if(!T(n))throw new TypeError(y('1RZ3q',n));return D(m,v,i,s,u);function u(g,o){if(g)return n(g);n(null,o)}}}F.exports=G -});var N=c(function(Y,C){ -var p=q();function H(e,r,i,t,s){if(arguments.length<5)return p(i)(e,r,t);p(i,t)(e,r,s)}C.exports=H -});var K=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),V=N(),M=q();K(V,"factory",M);module.exports=V; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index acb9d67..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/limit.js", "../lib/factory.js", "../lib/main.js", "../lib/index.js"], - "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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\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 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 to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\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 === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, 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 ( !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, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\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* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nmodule.exports = reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' );\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, 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"], - "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,0BAA2B,EAkB/C,SAASE,EAAOC,EAAYC,EAAKC,EAAMC,EAAKC,EAAO,CAClD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMR,EAAW,OACjBF,EAAO,wBAAyBU,CAAI,EAE/BA,IAAQ,EACZ,OAAAV,EAAO,mCAAoC,EACpCM,EAAM,KAAMH,CAAI,EAYxB,IAVKO,EAAMN,EAAK,MACfK,EAAMC,EAEND,EAAML,EAAK,MAEZJ,EAAO,wBAAyBS,CAAI,EACpCT,EAAO,0BAA2BK,EAAI,MAAO,EAE7CE,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVE,EAAK,EAQP,SAASA,GAAO,CACfF,GAAO,EACPX,EAAO,6BAA8BW,EAAK,KAAK,UAAWT,EAAYS,CAAI,CAAE,CAAE,EACzEN,EAAI,SAAW,EACnBA,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGG,CAAG,EACxCT,EAAI,SAAW,EAC1BA,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGA,EAAKG,CAAG,EAExDT,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGA,EAAKT,EAAYY,CAAG,EAUrE,SAASA,EAAIC,EAAOC,EAAS,CAC5B,GAAK,CAAAR,EAIL,IAAKO,EACJ,OAAAP,EAAM,GACCS,EAAMF,CAAM,EAEpBf,EAAO,kBAAmB,KAAK,UAAWgB,CAAO,CAAE,EACnDb,EAAMa,EACNC,EAAK,EACN,CACD,CASA,SAASA,EAAMF,EAAQ,CACtB,GAAKA,EACJ,OAAAf,EAAO,2BAA4Be,EAAM,OAAQ,EAC1CT,EAAMS,CAAM,EAIpB,GAFAR,GAAS,EACTP,EAAO,0CAA2CO,EAAOG,CAAI,EACxDC,EAAM,EACV,OAAOE,EAAK,EAEb,GAAKN,IAAUG,EACd,OAAAV,EAAO,mCAAoC,EACpCM,EAAM,KAAMH,CAAI,CAEzB,CACD,CAKAL,EAAO,QAAUG,IC7IjB,IAAAiB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,gCAAiC,EACjDC,EAAW,IACXC,EAAQ,IAoEZ,SAASC,EAASC,EAASC,EAAM,CAChC,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,CAACP,EAAYW,CAAE,EACnB,MAAM,IAAI,UAAWT,EAAQ,mEAAoES,CAAE,CAAE,EAEtG,OAAKF,EAAK,SAAW,QAAUA,EAAK,QAAU,SAC7CA,EAAK,OAAS,IAEVA,EAAK,OACTA,EAAK,MAAQ,EACDA,EAAK,QACjBA,EAAK,MAAQN,GAEPS,EAaP,SAASA,EAAkBC,EAAYC,EAASC,EAAO,CACtD,GAAK,CAACd,EAAcY,CAAW,EAC9B,MAAM,IAAI,UAAWX,EAAQ,sEAAuEW,CAAW,CAAE,EAElH,GAAK,CAACb,EAAYe,CAAK,EACtB,MAAM,IAAI,UAAWb,EAAQ,mEAAoEa,CAAK,CAAE,EAEzG,OAAOV,EAAOQ,EAAYC,EAASL,EAAME,EAAGK,CAAK,EAUjD,SAASA,EAAMC,EAAOC,EAAM,CAC3B,GAAKD,EACJ,OAAOF,EAAME,CAAM,EAEpBF,EAAM,KAAMG,CAAI,CACjB,CACD,CACD,CAKAnB,EAAO,QAAUO,ICnKjB,IAAAa,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,IA8Dd,SAASC,EAAkBC,EAAYC,EAASC,EAASC,EAAKC,EAAO,CACpE,GAAK,UAAU,OAAS,EACvB,OAAON,EAASI,CAAQ,EAAGF,EAAYC,EAASE,CAAI,EAErDL,EAASI,EAASC,CAAI,EAAGH,EAAYC,EAASG,CAAK,CACpD,CAKAP,EAAO,QAAUE,IC9BjB,IAAIM,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "isPositiveInteger", "format", "validate", "opts", "options", "require_limit", "__commonJSMin", "exports", "module", "logger", "debug", "limit", "collection", "acc", "opts", "fcn", "done", "count", "flg", "lim", "len", "idx", "i", "next", "cb", "error", "result", "clbk", "require_factory", "__commonJSMin", "exports", "module", "isFunction", "isCollection", "format", "PINF", "validate", "limit", "factory", "options", "fcn", "opts", "err", "f", "reduceRightAsync", "collection", "initial", "done", "clbk", "error", "acc", "require_main", "__commonJSMin", "exports", "module", "factory", "reduceRightAsync", "collection", "initial", "options", "fcn", "done", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3f22669..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,224 +0,0 @@ - -{{alias}}( collection, initial, [options,] reducer, done ) - Applies a function against an accumulator and each element in a collection - and returns the accumulated result, iterating from right to left. - - When invoked, `reducer` is provided a maximum of five arguments: - - - `accumulator`: accumulated value - - `value`: collection value - - `index`: collection index - - `collection`: the input collection - - `next`: a callback to be invoked after processing a collection `value` - - The actual number of provided arguments depends on function length. If - `reducer` accepts three arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `next` - - If `reducer` accepts four arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `index` - - `next` - - For every other `reducer` signature, `reducer` is provided all five - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `accumulator`: accumulated value - - If a provided function calls the `next` callback with a truthy `error` - argument, the function suspends execution and immediately calls the `done` - callback for subsequent `error` handling. - - Execution is *not* guaranteed to be asynchronous. To guarantee asynchrony, - 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`). - - The function does not support dynamic collection resizing. - - If provided an empty collection, the function invokes the `done` callback - with the `initial` value as the second argument. - - The function does not skip `undefined` elements. - - When processing collection elements concurrently, *beware* of race - conditions when updating an accumulator. This is especially true when an - accumulator is a primitive (e.g., a number). In general, prefer object - accumulators. - - Parameters - ---------- - collection: Array|TypedArray|Object - Input collection over which to iterate. If provided an object, the - object must be array-like (excluding strings and functions). - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - reducer: Function - The function to invoke for each element in a collection. - - done: Function - A callback invoked either upon processing all collection elements or - upon encountering an error. - - Examples - -------- - // Basic usage: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, fcn, done ) - 3000 - 2500 - 1000 - 6500 - - // Limit number of concurrent invocations: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'limit': 2 }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 2500 - 3000 - 1000 - 6500 - - // Process concurrently: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'series': false }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 1000 - 2500 - 3000 - 6500 - - -{{alias}}.factory( [options,] fcn ) - Returns a function which applies a function against an accumulator and each - element in a collection and returns the accumulated result, iterating from - right to left. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - fcn: Function - The function to invoke for each element in a collection. - - Returns - ------- - out: Function - A function which invokes a function for each element in a collection. - - Examples - -------- - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > var opts = { 'series': false }; - > var f = {{alias}}.factory( opts, fcn ); - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > f( arr, acc, done ) - 1000 - 2500 - 3000 - 6500 - > acc = { 'sum': 0 }; - > arr = [ 1000, 1500, 2000 ]; - > f( arr, acc, done ) - 1000 - 1500 - 2000 - 4500 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0455864..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,166 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unsafe-assignment */ - -import reduceRightAsync = require( './index' ); - -const reducer = ( acc: any, value: number, index: number, next: Function ) => { - acc.sum += value; - if ( index === void 0 ) { - throw new Error( '`index` is missing.' ); - } - next( null, acc ); -}; - -const done = ( error: Error | null, acc: any ) => { - if ( error ) { - throw error; - } - if ( acc === void 0 ) { - throw new Error( '`acc` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( 2, acc, reducer, done ); // $ExpectError - reduceRightAsync( false, acc, reducer, done ); // $ExpectError - reduceRightAsync( true, acc, reducer, done ); // $ExpectError - reduceRightAsync( {}, acc, reducer, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a predicate argument which is not a predicate function... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 2, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, false, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, true, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 'abc', done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, [], done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a done callback argument which is not a function having a supported signature... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 2 ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, false ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, true ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 'abc' ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, {} ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, [] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const acc = { 'sum': 0 }; - reduceRightAsync(); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, reducer, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - reduceRightAsync.factory( reducer ); // $ExpectType FactoryFunction - reduceRightAsync.factory( { 'series': true }, reducer ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - reduceRightAsync.factory( [], reducer ); // $ExpectError - reduceRightAsync.factory( 123, reducer ); // $ExpectError - reduceRightAsync.factory( 'abc', reducer ); // $ExpectError - reduceRightAsync.factory( false, reducer ); // $ExpectError - reduceRightAsync.factory( true, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not a predicate function... -{ - reduceRightAsync.factory( {} ); // $ExpectError - reduceRightAsync.factory( true ); // $ExpectError - reduceRightAsync.factory( false ); // $ExpectError - reduceRightAsync.factory( {}, 123 ); // $ExpectError - reduceRightAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1( 12, acc, done ); // $ExpectError - fcn1( true, acc, done ); // $ExpectError - fcn1( false, acc, done ); // $ExpectError - fcn1( {}, acc, done ); // $ExpectError - - fcn1( [ 3000, 2500, 1000 ], acc, 12 ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, true ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, false ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, '5' ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, {} ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, [] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1(); // $ExpectError - fcn1( [ 3000, 2500, 1000 ] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - reduceRightAsync.factory( { 'limit': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': true }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': false }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - reduceRightAsync.factory( { 'series': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': 12 }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - reduceRightAsync.factory(); // $ExpectError - reduceRightAsync.factory( {}, reducer, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index dd64345..0000000 --- a/examples/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var resolve = require( 'path' ).resolve; -var readFile = require( '@stdlib/fs-read-file' ); -var reduceRightAsync = require( './../lib' ); - -var files = [ - resolve( __dirname, '..', 'package.json' ), - resolve( __dirname, '..', 'README.md' ) -]; - -function done( error, acc ) { - if ( error ) { - throw error; - } - console.log( acc.count ); -} - -function read( acc, file, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( file, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( null, acc ); - } - acc.count += 1; - next( null, acc ); - } -} - -var acc = { - 'count': 0 -}; -reduceRightAsync( files, acc, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 16e0539..816cbe3 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..48ff8e2 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import{isPrimitive as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.1.0-esm/index.mjs";function a(e,t){return s(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(n("invalid option. `%s` option must be a boolean. Option: `%s`.","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!m(e.limit))?new TypeError(n("invalid option. `%s` option must be a positive integer. Option: `%s`.","limit",e.limit)):null):new TypeError(n("invalid argument. Options argument must be an object. Value: `%s`.",t))}function u(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){if(this instanceof e){var i=[null];i.push.apply(i,arguments);var n=Function.bind.apply(t,i);return new n}return t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})})),i}var d=u(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function c(e,t,i,n,r){var s,o,l,m,a,u;if(m=e.length,d("Collection length: %d",m),0===m)return d("Finished processing a collection."),r(null,t);for(l=m0&&c();function c(){function r(e,i){if(!o){if(e)return o=!0,p(e);d("Accumulator: %s",JSON.stringify(i)),t=i,p()}}d("Collection element %d: %s.",a-=1,JSON.stringify(e[a])),3===n.length?n.call(i.thisArg,t,e[a],r):4===n.length?n.call(i.thisArg,t,e[a],a,r):n.call(i.thisArg,t,e[a],a,e,r)}function p(e){return e?(d("Encountered an error: %s",e.message),r(e)):(d("Processed %d of %d collection elements.",s+=1,m),a>0?c():s===m?(d("Finished processing a collection."),r(null,t)):void 0)}}function p(e,s){var o,l,m;if(o={},arguments.length>1){if(l=a(o,e))throw l;m=s}else m=e;if(!t(m))throw new TypeError(n("invalid argument. Last argument must be a function. Value: `%s`.",m));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=r),u;function u(e,r,s){if(!i(e))throw new TypeError(n("invalid argument. First argument must be a collection. Value: `%s`.",e));if(!t(s))throw new TypeError(n("invalid argument. Last argument must be a function. Value: `%s`.",s));return c(e,r,o,m,(function(e,t){if(e)return s(e);s(null,t)}))}}function f(e,t,i,n,r){if(arguments.length<5)return p(i)(e,t,n);p(i,n)(e,t,r)}e(f,"factory",p);export{f as default,p as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..42fb408 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@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\nexport default 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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/string-format';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\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 === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, 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 ( !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, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","logger","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly","main"],"mappings":";;+4BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,+DAAgE,SAAUR,EAAKK,SAG1GF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,wEAAyE,QAASR,EAAKS,QAGhH,MAjBC,IAAIF,UAAWC,EAAQ,qEAAsEP,GAkBtG,8eC/CIU,uDAAQC,CAAQ,4BAkBpB,SAASH,EAAOI,EAAYC,EAAKd,EAAMe,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMP,EAAWU,OACjBZ,EAAO,wBAAyBS,GAEnB,IAARA,EAEJ,OADAT,EAAO,qCACAK,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAEZE,EAAO,wBAAyBQ,GAChCR,EAAO,0BAA2BI,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdf,EAAO,kBAAmBkB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,GAPC,CAQD,CA5BDjB,EAAO,6BADPU,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJf,EAAO,2BAA4Be,EAAMM,SAClChB,EAAMU,KAGdf,EAAO,0CADPM,GAAS,EACgDG,GACpDC,EAAM,EACHG,IAEHP,IAAUG,GACdT,EAAO,qCACAK,EAAM,KAAMF,SAFpB,EAIA,CACF,CCzCA,SAASmB,EAAShC,EAASc,GAC1B,IAAIf,EACAkC,EACAC,EAGJ,GADAnC,EAAO,CAAA,EACFoC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMnC,EAAUC,EAAMC,GAErB,MAAMiC,EAEPC,EAAIpB,CACN,MACEoB,EAAIlC,EAEL,IAAMoC,EAAYF,GACjB,MAAM,IAAI5B,UAAWC,EAAQ,mEAAoE2B,IAUlG,YARqB,IAAhBnC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ6B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIN,UAAWC,EAAQ,sEAAuEK,IAErG,IAAMwB,EAAYrB,GACjB,MAAM,IAAIT,UAAWC,EAAQ,mEAAoEQ,IAElG,OAAOP,EAAOI,EAAY2B,EAASxC,EAAMmC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,EACZ,GACD,CACF,CC1EA,SAASyB,EAAkB1B,EAAY2B,EAASvC,EAASc,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAShC,EAATgC,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAShC,EAASc,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,EAC/C,CClBA0B,EAAAC,EAAA,UAAAV"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 1125052..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,164 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/string-format' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var validate = require( './validate.js' ); -var limit = require( './limit.js' ); - - -// MAIN // - -/** -* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} last argument must be a function -* @returns {Function} function which invokes the provided function once for each element in a collection -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error, data ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var opts = { -* 'series': false -* }; -* -* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: -* var reduceRightAsync = factory( opts, read ); -* -* // Create a collection over which to iterate: -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* // Define a callback which handles errors: -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* // Run `read` for each element in `files`: -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, done ); -*/ -function factory( options, fcn ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = fcn; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); - } - if ( opts.series === void 0 && opts.limit === void 0 ) { - opts.series = true; - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return reduceRightAsync; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * @private - * @param {Collection} collection - input collection - * @param {*} initial - initial value - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be a collection - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function reduceRightAsync( collection, initial, done ) { - if ( !isCollection( collection ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a collection. Value: `%s`.', collection ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); - } - return limit( collection, initial, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {*} [acc] - accumulated value - * @returns {void} - */ - function clbk( error, acc ) { - if ( error ) { - return done( error ); - } - done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ae657ff..0000000 --- a/lib/index.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* @module @stdlib/utils-async-reduce-right -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' ); -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/limit.js b/lib/limit.js deleted file mode 100644 index cdb60af..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); - - -// VARIABLES // - -var debug = logger( 'reduce-right-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each element in a collection, limiting the number of concurrently pending functions and iterating from right to left. -* -* @private -* @param {Collection} collection - input collection -* @param {*} acc - initial value -* @param {Options} opts - function options -* @param {*} [opts.thisArg] - execution context -* @param {PositiveInteger} [opts.limit] - maximum number of pending function invocations -* @param {Function} fcn - function to invoke -* @param {Callback} done - function to invoke upon completion or upon encountering an error -* @returns {void} -*/ -function limit( collection, acc, opts, fcn, done ) { - var count; - var flg; - var lim; - var len; - var idx; - var i; - - len = collection.length; - debug( 'Collection length: %d', len ); - - if ( len === 0 ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - count = 0; - idx = len; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all collection elements... - if ( idx > 0 ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next element in a collection. - * - * @private - */ - function next() { - idx -= 1; - debug( 'Collection element %d: %s.', idx, JSON.stringify( collection[ idx ] ) ); - if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], cb ); - } else if ( fcn.length === 4 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, cb ); - } else { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len - } - /** - * Callback invoked once a provided function finishes processing a collection element. - * - * @private - * @param {*} [error] - error - * @param {*} [result] - accumulation result - * @returns {void} - */ - function cb( error, result ) { - if ( flg ) { - // Prevent further processing of collection elements: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Accumulator: %s', JSON.stringify( result ) ); - acc = result; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next collection element. - * - * @private - * @param {*} [error] - error - * @returns {void} - */ - function clbk( error ) { - if ( error ) { - debug( 'Encountered an error: %s', error.message ); - return done( error ); - } - count += 1; - debug( 'Processed %d of %d collection elements.', count, len ); - if ( idx > 0 ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index c8b0d0f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param {Collection} collection - input collection -* @param {*} initial - initial value -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} second-to-last argument must be a function -* @throws {TypeError} last argument must be a function -* @returns {void} -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -function reduceRightAsync( collection, initial, options, fcn, done ) { - if ( arguments.length < 5 ) { - return factory( options )( collection, initial, fcn ); - } - factory( options, fcn )( collection, initial, done ); -} - - -// EXPORTS // - -module.exports = reduceRightAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 9ba927e..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @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 -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'thisArg': {}, -* 'series': false, -* 'limit': 10 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp( options, 'thisArg' ) ) { - opts.thisArg = options.thisArg; - } - if ( hasOwnProp( options, 'series' ) ) { - opts.series = options.series; - if ( !isBoolean( opts.series ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index a3e4906..d4f9525 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,43 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-boolean": "^0.1.1", - "@stdlib/assert-is-collection": "^0.1.0", - "@stdlib/assert-is-function": "^0.1.1", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/assert-is-positive-integer": "^0.1.0", - "@stdlib/constants-float64-pinf": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.2.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/constants-float64-eps": "^0.1.1", - "@stdlib/fs-read-file": "^0.1.1", - "@stdlib/utils-noop": "^0.1.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.1.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..8e59e4a --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 8244931..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1095 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( {}, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, next ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - factory( opts, next ); - }; - } -}); - -tape( 'the function returns a function (no options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided a collection (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a collection (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (1 argument)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (2 arguments)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with five arguments', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn() { - var value; - var next; - var acc; - var k; - - acc = arguments[ 0 ]; - value = arguments[ 1 ]; - k = arguments[ 2 ]; - next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( k, i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the returned function supports processing collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements concurrently', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 100, 250, 300 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements sequentially (limit = 1)', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of collection elements which are processed at any one time', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 250, 300, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 250, 100, 300 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var reduceRightAsync; - var arr; - - reduceRightAsync = factory( fcn ); - arr = []; - - reduceRightAsync( arr, 0, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var reduceRightAsync; - var obj; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = []; - obj = {}; - reduceRightAsync( arr, obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - i = 0; - - reduceRightAsync( arr, {}, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, acc ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the returned function does not skip empty elements', function test( t ) { - var reduceRightAsync; - var expected; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index f273a40..0000000 --- a/test/test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof reduceRightAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 1893240..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1035 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a collection', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (no options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, next, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, 0 ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - reduceRightAsync( [ 1, 2, 3 ], 0, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (1 argument)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (2 arguments)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with five arguments', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn() { - var next; - var acc; - var v; - - next = arguments[ 4 ]; - acc = arguments[ 0 ]; - v = arguments[ 1 ]; - - i -= 1; - j += 1; - - t.strictEqual( v, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, v ); - - function onTimeout() { - acc.sum += v; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'by default, the function processes collection elements sequentially', function test( t ) { - var values; - var count; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements concurrently', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 100, 250, 300 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': true - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially (limit = 1)', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var arr; - var ctx; - - arr = [ 3, 2, 1 ]; - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 3, 2, 1 ]; - opts = { - 'series': true - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 250, 100, 300 ]; - opts = { - 'limit': 2 - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var arr = []; - reduceRightAsync( arr, 0, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var arr = []; - var obj = {}; - - reduceRightAsync( arr, obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - arr = [ 3, 2, 1 ]; - i = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, value ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the function does not skip empty elements', function test( t ) { - var expected; - var arr; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, fcn, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 7660838..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,181 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `limit` option which is not a positive integer', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - -5, - 0, - 3.14, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'limit': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `series` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'series': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function accepts any value for the `thisArg` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'thisArg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err, null, 'returns null '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'thisArg': {}, - 'series': false, - 'limit': 10 - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From b9e9167d6859fa9ce46cb9b17d7c530d533abf64 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 04:45:30 +0000 Subject: [PATCH 091/147] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 18a98c9..a3e4906 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-plain-object": "^0.1.1", "@stdlib/assert-is-positive-integer": "^0.1.0", "@stdlib/constants-float64-pinf": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1", "debug": "^2.6.9" From 52f505590feb811b34c7918762164a5412a1e5c2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 09:55:57 +0000 Subject: [PATCH 092/147] Remove files --- index.d.ts | 410 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6592 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 816cbe3..0000000 --- a/index.d.ts +++ /dev/null @@ -1,410 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Execution context. - */ - thisArg?: ThisParameterType>; - - /** - * The maximum number of pending invocations at any one time. - */ - limit?: number; - - /** - * Boolean indicating whether to sequentially invoke the reducer function for each `collection` element. If `true`, the function sets `options.limit=1`. Default: true. - */ - series?: boolean; -} - -/** -* Callback function. -*/ -type Nullary = () => void; - -/** -* Callback function. -* -* @param error - encountered error or null -*/ -type Unary = ( error: Error | null ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Binary = ( error: Error | null, accumulator: U ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param next - a callback to be invoked after processing a collection `value` -*/ -type TernaryReducer = ( this: V, accumulator: U, value: T, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuaternaryReducer = ( this: V, accumulator: U, value: T, index: number, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuinaryReducer = ( this: V, accumulator: U, value: T, index: number, collection: Collection, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type Reducer = TernaryReducer | QuaternaryReducer | QuinaryReducer; - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result. -* -* @param collection - input collection -* @param initial - initial value -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( collection: Collection, initial: U, done: Callback ) => void; - -/** -* Interface for `reduceRightAsync`. -*/ -interface ReduceRightAsync { - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, {}, read, done ); - */ - ( collection: Collection, initial: U, options: Options, reducer: Reducer, done: Callback ): void; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, read, done ); - */ - ( collection: Collection, initial: U, reducer: Reducer, done: Callback ): void; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @throws must provide valid options - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var opts = { - * 'series': false - * }; - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( opts, read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( options: Options, reducer: Reducer ): FactoryFunction; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param reducer - function to invoke for each element in a collection - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( reducer: Reducer ): FactoryFunction; -} - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param collection - input collection -* @param initial - initial value -* @param options - function options -* @param options.thisArg - execution context -* @param options.limit - maximum number of pending invocations at any one time -* @param 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 (default: true) -* @param reducer - function to invoke for each element in a collection -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( `@stdlib/fs/read-file` ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -declare var reduceRightAsync: ReduceRightAsync; - - -// EXPORTS // - -export = reduceRightAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 48ff8e2..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import{isPrimitive as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.1.0-esm/index.mjs";function a(e,t){return s(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(n("invalid option. `%s` option must be a boolean. Option: `%s`.","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!m(e.limit))?new TypeError(n("invalid option. `%s` option must be a positive integer. Option: `%s`.","limit",e.limit)):null):new TypeError(n("invalid argument. Options argument must be an object. Value: `%s`.",t))}function u(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){if(this instanceof e){var i=[null];i.push.apply(i,arguments);var n=Function.bind.apply(t,i);return new n}return t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})})),i}var d=u(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function c(e,t,i,n,r){var s,o,l,m,a,u;if(m=e.length,d("Collection length: %d",m),0===m)return d("Finished processing a collection."),r(null,t);for(l=m0&&c();function c(){function r(e,i){if(!o){if(e)return o=!0,p(e);d("Accumulator: %s",JSON.stringify(i)),t=i,p()}}d("Collection element %d: %s.",a-=1,JSON.stringify(e[a])),3===n.length?n.call(i.thisArg,t,e[a],r):4===n.length?n.call(i.thisArg,t,e[a],a,r):n.call(i.thisArg,t,e[a],a,e,r)}function p(e){return e?(d("Encountered an error: %s",e.message),r(e)):(d("Processed %d of %d collection elements.",s+=1,m),a>0?c():s===m?(d("Finished processing a collection."),r(null,t)):void 0)}}function p(e,s){var o,l,m;if(o={},arguments.length>1){if(l=a(o,e))throw l;m=s}else m=e;if(!t(m))throw new TypeError(n("invalid argument. Last argument must be a function. Value: `%s`.",m));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=r),u;function u(e,r,s){if(!i(e))throw new TypeError(n("invalid argument. First argument must be a collection. Value: `%s`.",e));if(!t(s))throw new TypeError(n("invalid argument. Last argument must be a function. Value: `%s`.",s));return c(e,r,o,m,(function(e,t){if(e)return s(e);s(null,t)}))}}function f(e,t,i,n,r){if(arguments.length<5)return p(i)(e,t,n);p(i,n)(e,t,r)}e(f,"factory",p);export{f as default,p as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 42fb408..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@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\nexport default 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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/string-format';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\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 === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, 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 ( !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, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","logger","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly","main"],"mappings":";;+4BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,+DAAgE,SAAUR,EAAKK,SAG1GF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,wEAAyE,QAASR,EAAKS,QAGhH,MAjBC,IAAIF,UAAWC,EAAQ,qEAAsEP,GAkBtG,8eC/CIU,uDAAQC,CAAQ,4BAkBpB,SAASH,EAAOI,EAAYC,EAAKd,EAAMe,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMP,EAAWU,OACjBZ,EAAO,wBAAyBS,GAEnB,IAARA,EAEJ,OADAT,EAAO,qCACAK,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAEZE,EAAO,wBAAyBQ,GAChCR,EAAO,0BAA2BI,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdf,EAAO,kBAAmBkB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,GAPC,CAQD,CA5BDjB,EAAO,6BADPU,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJf,EAAO,2BAA4Be,EAAMM,SAClChB,EAAMU,KAGdf,EAAO,0CADPM,GAAS,EACgDG,GACpDC,EAAM,EACHG,IAEHP,IAAUG,GACdT,EAAO,qCACAK,EAAM,KAAMF,SAFpB,EAIA,CACF,CCzCA,SAASmB,EAAShC,EAASc,GAC1B,IAAIf,EACAkC,EACAC,EAGJ,GADAnC,EAAO,CAAA,EACFoC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMnC,EAAUC,EAAMC,GAErB,MAAMiC,EAEPC,EAAIpB,CACN,MACEoB,EAAIlC,EAEL,IAAMoC,EAAYF,GACjB,MAAM,IAAI5B,UAAWC,EAAQ,mEAAoE2B,IAUlG,YARqB,IAAhBnC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ6B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIN,UAAWC,EAAQ,sEAAuEK,IAErG,IAAMwB,EAAYrB,GACjB,MAAM,IAAIT,UAAWC,EAAQ,mEAAoEQ,IAElG,OAAOP,EAAOI,EAAY2B,EAASxC,EAAMmC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,EACZ,GACD,CACF,CC1EA,SAASyB,EAAkB1B,EAAY2B,EAASvC,EAASc,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAShC,EAATgC,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAShC,EAASc,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,EAC/C,CClBA0B,EAAAC,EAAA,UAAAV"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 8e59e4a..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 26db216e8b45483cb1dee291d2490c3a6b22c43c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 09:56:11 +0000 Subject: [PATCH 093/147] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.factory.js | 73 - benchmark/benchmark.js | 160 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 224 - docs/types/test.ts | 166 - examples/index.js | 55 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 164 - lib/index.js | 77 - lib/limit.js | 142 - lib/main.js | 95 - lib/validate.js | 80 - package.json | 64 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 1095 ---- test/test.js | 38 - test/test.main.js | 1035 ---- test/test.validate.js | 181 - 50 files changed, 6208 insertions(+), 6953 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/limit.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index a4e836f..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-02-01T03:13:15.004Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1e08946..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 30656c4..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 5358060..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c92f5c4..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 0083051..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '37 1 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index e1e3539..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -460,7 +457,7 @@ reduceRightAsync( files, acc, read, done ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -531,11 +528,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right +[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right/tree/esm -[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce +[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index b155fd2..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var reduceRightAsync; - var arr; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - reduceRightAsync = factory( onItem ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - var acc; - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index af5c346..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var reduceRightAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=false', function benchmark( b ) { - var opts; - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'series': false - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var arr; - var len; - var acc; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'limit': 3 - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b8adcd2..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right" -%% click B href "https://github.com/stdlib-js/utils-async-reduce-right/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-reduce-right/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-reduce-right/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-reduce-right/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right -[production-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-async-reduce-right/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-async-reduce-right/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-async-reduce-right/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 47a072e..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import reduceRightAsync from '../docs/types/index'; -export = reduceRightAsync; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 530ca4d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var c=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var x=c(function(U,O){ -var R=require('@stdlib/assert-is-plain-object/dist'),h=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,k=require('@stdlib/assert-is-positive-integer/dist').isPrimitive,d=require('@stdlib/error-tools-fmtprodmsg/dist');function I(e,r){return R(r)?(h(r,"thisArg")&&(e.thisArg=r.thisArg),h(r,"series")&&(e.series=r.series,!j(e.series))?new TypeError(d('1RZ2o',"series",e.series)):h(r,"limit")&&(e.limit=r.limit,!k(e.limit))?new TypeError(d('1RZ3P',"limit",e.limit)):null):new TypeError(d('1RZ2V',r));}O.exports=I -});var P=c(function(W,E){ -var J=require("debug"),a=J("reduce-right-async:limit");function L(e,r,i,t,s){var f,m,v,n,u,g;if(n=e.length,a("Collection length: %d",n),n===0)return a("Finished processing a collection."),s(null,r);for(n0&&o();function o(){u-=1,a("Collection element %d: %s.",u,JSON.stringify(e[u])),t.length===3?t.call(i.thisArg,r,e[u],l):t.length===4?t.call(i.thisArg,r,e[u],u,l):t.call(i.thisArg,r,e[u],u,e,l);function l(w,A){if(!m){if(w)return m=!0,b(w);a("Accumulator: %s",JSON.stringify(A)),r=A,b()}}}function b(l){if(l)return a("Encountered an error: %s",l.message),s(l);if(f+=1,a("Processed %d of %d collection elements.",f,n),u>0)return o();if(f===n)return a("Finished processing a collection."),s(null,r)}}E.exports=L -});var q=c(function(X,F){ -var T=require('@stdlib/assert-is-function/dist'),S=require('@stdlib/assert-is-collection/dist'),y=require('@stdlib/error-tools-fmtprodmsg/dist'),B=require('@stdlib/constants-float64-pinf/dist'),z=x(),D=P();function G(e,r){var i,t,s;if(i={},arguments.length>1){if(t=z(i,e),t)throw t;s=r}else s=e;if(!T(s))throw new TypeError(y('1RZ3q',s));return i.series===void 0&&i.limit===void 0&&(i.series=!0),i.series?i.limit=1:i.limit||(i.limit=B),f;function f(m,v,n){if(!S(m))throw new TypeError(y('1RZAh',m));if(!T(n))throw new TypeError(y('1RZ3q',n));return D(m,v,i,s,u);function u(g,o){if(g)return n(g);n(null,o)}}}F.exports=G -});var N=c(function(Y,C){ -var p=q();function H(e,r,i,t,s){if(arguments.length<5)return p(i)(e,r,t);p(i,t)(e,r,s)}C.exports=H -});var K=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),V=N(),M=q();K(V,"factory",M);module.exports=V; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index acb9d67..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/limit.js", "../lib/factory.js", "../lib/main.js", "../lib/index.js"], - "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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\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 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 to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\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 === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, 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 ( !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, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\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* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nmodule.exports = reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' );\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, 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"], - "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,0BAA2B,EAkB/C,SAASE,EAAOC,EAAYC,EAAKC,EAAMC,EAAKC,EAAO,CAClD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMR,EAAW,OACjBF,EAAO,wBAAyBU,CAAI,EAE/BA,IAAQ,EACZ,OAAAV,EAAO,mCAAoC,EACpCM,EAAM,KAAMH,CAAI,EAYxB,IAVKO,EAAMN,EAAK,MACfK,EAAMC,EAEND,EAAML,EAAK,MAEZJ,EAAO,wBAAyBS,CAAI,EACpCT,EAAO,0BAA2BK,EAAI,MAAO,EAE7CE,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVE,EAAK,EAQP,SAASA,GAAO,CACfF,GAAO,EACPX,EAAO,6BAA8BW,EAAK,KAAK,UAAWT,EAAYS,CAAI,CAAE,CAAE,EACzEN,EAAI,SAAW,EACnBA,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGG,CAAG,EACxCT,EAAI,SAAW,EAC1BA,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGA,EAAKG,CAAG,EAExDT,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGA,EAAKT,EAAYY,CAAG,EAUrE,SAASA,EAAIC,EAAOC,EAAS,CAC5B,GAAK,CAAAR,EAIL,IAAKO,EACJ,OAAAP,EAAM,GACCS,EAAMF,CAAM,EAEpBf,EAAO,kBAAmB,KAAK,UAAWgB,CAAO,CAAE,EACnDb,EAAMa,EACNC,EAAK,EACN,CACD,CASA,SAASA,EAAMF,EAAQ,CACtB,GAAKA,EACJ,OAAAf,EAAO,2BAA4Be,EAAM,OAAQ,EAC1CT,EAAMS,CAAM,EAIpB,GAFAR,GAAS,EACTP,EAAO,0CAA2CO,EAAOG,CAAI,EACxDC,EAAM,EACV,OAAOE,EAAK,EAEb,GAAKN,IAAUG,EACd,OAAAV,EAAO,mCAAoC,EACpCM,EAAM,KAAMH,CAAI,CAEzB,CACD,CAKAL,EAAO,QAAUG,IC7IjB,IAAAiB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,gCAAiC,EACjDC,EAAW,IACXC,EAAQ,IAoEZ,SAASC,EAASC,EAASC,EAAM,CAChC,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,CAACP,EAAYW,CAAE,EACnB,MAAM,IAAI,UAAWT,EAAQ,mEAAoES,CAAE,CAAE,EAEtG,OAAKF,EAAK,SAAW,QAAUA,EAAK,QAAU,SAC7CA,EAAK,OAAS,IAEVA,EAAK,OACTA,EAAK,MAAQ,EACDA,EAAK,QACjBA,EAAK,MAAQN,GAEPS,EAaP,SAASA,EAAkBC,EAAYC,EAASC,EAAO,CACtD,GAAK,CAACd,EAAcY,CAAW,EAC9B,MAAM,IAAI,UAAWX,EAAQ,sEAAuEW,CAAW,CAAE,EAElH,GAAK,CAACb,EAAYe,CAAK,EACtB,MAAM,IAAI,UAAWb,EAAQ,mEAAoEa,CAAK,CAAE,EAEzG,OAAOV,EAAOQ,EAAYC,EAASL,EAAME,EAAGK,CAAK,EAUjD,SAASA,EAAMC,EAAOC,EAAM,CAC3B,GAAKD,EACJ,OAAOF,EAAME,CAAM,EAEpBF,EAAM,KAAMG,CAAI,CACjB,CACD,CACD,CAKAnB,EAAO,QAAUO,ICnKjB,IAAAa,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,IA8Dd,SAASC,EAAkBC,EAAYC,EAASC,EAASC,EAAKC,EAAO,CACpE,GAAK,UAAU,OAAS,EACvB,OAAON,EAASI,CAAQ,EAAGF,EAAYC,EAASE,CAAI,EAErDL,EAASI,EAASC,CAAI,EAAGH,EAAYC,EAASG,CAAK,CACpD,CAKAP,EAAO,QAAUE,IC9BjB,IAAIM,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "isPositiveInteger", "format", "validate", "opts", "options", "require_limit", "__commonJSMin", "exports", "module", "logger", "debug", "limit", "collection", "acc", "opts", "fcn", "done", "count", "flg", "lim", "len", "idx", "i", "next", "cb", "error", "result", "clbk", "require_factory", "__commonJSMin", "exports", "module", "isFunction", "isCollection", "format", "PINF", "validate", "limit", "factory", "options", "fcn", "opts", "err", "f", "reduceRightAsync", "collection", "initial", "done", "clbk", "error", "acc", "require_main", "__commonJSMin", "exports", "module", "factory", "reduceRightAsync", "collection", "initial", "options", "fcn", "done", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3f22669..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,224 +0,0 @@ - -{{alias}}( collection, initial, [options,] reducer, done ) - Applies a function against an accumulator and each element in a collection - and returns the accumulated result, iterating from right to left. - - When invoked, `reducer` is provided a maximum of five arguments: - - - `accumulator`: accumulated value - - `value`: collection value - - `index`: collection index - - `collection`: the input collection - - `next`: a callback to be invoked after processing a collection `value` - - The actual number of provided arguments depends on function length. If - `reducer` accepts three arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `next` - - If `reducer` accepts four arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `index` - - `next` - - For every other `reducer` signature, `reducer` is provided all five - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `accumulator`: accumulated value - - If a provided function calls the `next` callback with a truthy `error` - argument, the function suspends execution and immediately calls the `done` - callback for subsequent `error` handling. - - Execution is *not* guaranteed to be asynchronous. To guarantee asynchrony, - 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`). - - The function does not support dynamic collection resizing. - - If provided an empty collection, the function invokes the `done` callback - with the `initial` value as the second argument. - - The function does not skip `undefined` elements. - - When processing collection elements concurrently, *beware* of race - conditions when updating an accumulator. This is especially true when an - accumulator is a primitive (e.g., a number). In general, prefer object - accumulators. - - Parameters - ---------- - collection: Array|TypedArray|Object - Input collection over which to iterate. If provided an object, the - object must be array-like (excluding strings and functions). - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - reducer: Function - The function to invoke for each element in a collection. - - done: Function - A callback invoked either upon processing all collection elements or - upon encountering an error. - - Examples - -------- - // Basic usage: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, fcn, done ) - 3000 - 2500 - 1000 - 6500 - - // Limit number of concurrent invocations: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'limit': 2 }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 2500 - 3000 - 1000 - 6500 - - // Process concurrently: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'series': false }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 1000 - 2500 - 3000 - 6500 - - -{{alias}}.factory( [options,] fcn ) - Returns a function which applies a function against an accumulator and each - element in a collection and returns the accumulated result, iterating from - right to left. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - fcn: Function - The function to invoke for each element in a collection. - - Returns - ------- - out: Function - A function which invokes a function for each element in a collection. - - Examples - -------- - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > var opts = { 'series': false }; - > var f = {{alias}}.factory( opts, fcn ); - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > f( arr, acc, done ) - 1000 - 2500 - 3000 - 6500 - > acc = { 'sum': 0 }; - > arr = [ 1000, 1500, 2000 ]; - > f( arr, acc, done ) - 1000 - 1500 - 2000 - 4500 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0455864..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,166 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unsafe-assignment */ - -import reduceRightAsync = require( './index' ); - -const reducer = ( acc: any, value: number, index: number, next: Function ) => { - acc.sum += value; - if ( index === void 0 ) { - throw new Error( '`index` is missing.' ); - } - next( null, acc ); -}; - -const done = ( error: Error | null, acc: any ) => { - if ( error ) { - throw error; - } - if ( acc === void 0 ) { - throw new Error( '`acc` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( 2, acc, reducer, done ); // $ExpectError - reduceRightAsync( false, acc, reducer, done ); // $ExpectError - reduceRightAsync( true, acc, reducer, done ); // $ExpectError - reduceRightAsync( {}, acc, reducer, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a predicate argument which is not a predicate function... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 2, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, false, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, true, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 'abc', done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, [], done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a done callback argument which is not a function having a supported signature... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 2 ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, false ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, true ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 'abc' ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, {} ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, [] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const acc = { 'sum': 0 }; - reduceRightAsync(); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, reducer, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - reduceRightAsync.factory( reducer ); // $ExpectType FactoryFunction - reduceRightAsync.factory( { 'series': true }, reducer ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - reduceRightAsync.factory( [], reducer ); // $ExpectError - reduceRightAsync.factory( 123, reducer ); // $ExpectError - reduceRightAsync.factory( 'abc', reducer ); // $ExpectError - reduceRightAsync.factory( false, reducer ); // $ExpectError - reduceRightAsync.factory( true, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not a predicate function... -{ - reduceRightAsync.factory( {} ); // $ExpectError - reduceRightAsync.factory( true ); // $ExpectError - reduceRightAsync.factory( false ); // $ExpectError - reduceRightAsync.factory( {}, 123 ); // $ExpectError - reduceRightAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1( 12, acc, done ); // $ExpectError - fcn1( true, acc, done ); // $ExpectError - fcn1( false, acc, done ); // $ExpectError - fcn1( {}, acc, done ); // $ExpectError - - fcn1( [ 3000, 2500, 1000 ], acc, 12 ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, true ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, false ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, '5' ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, {} ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, [] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1(); // $ExpectError - fcn1( [ 3000, 2500, 1000 ] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - reduceRightAsync.factory( { 'limit': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': true }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': false }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - reduceRightAsync.factory( { 'series': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': 12 }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - reduceRightAsync.factory(); // $ExpectError - reduceRightAsync.factory( {}, reducer, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index dd64345..0000000 --- a/examples/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var resolve = require( 'path' ).resolve; -var readFile = require( '@stdlib/fs-read-file' ); -var reduceRightAsync = require( './../lib' ); - -var files = [ - resolve( __dirname, '..', 'package.json' ), - resolve( __dirname, '..', 'README.md' ) -]; - -function done( error, acc ) { - if ( error ) { - throw error; - } - console.log( acc.count ); -} - -function read( acc, file, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( file, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( null, acc ); - } - acc.count += 1; - next( null, acc ); - } -} - -var acc = { - 'count': 0 -}; -reduceRightAsync( files, acc, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 28e0a36..f6cba5d 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..48ff8e2 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import{isPrimitive as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.1.0-esm/index.mjs";function a(e,t){return s(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(n("invalid option. `%s` option must be a boolean. Option: `%s`.","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!m(e.limit))?new TypeError(n("invalid option. `%s` option must be a positive integer. Option: `%s`.","limit",e.limit)):null):new TypeError(n("invalid argument. Options argument must be an object. Value: `%s`.",t))}function u(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){if(this instanceof e){var i=[null];i.push.apply(i,arguments);var n=Function.bind.apply(t,i);return new n}return t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})})),i}var d=u(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function c(e,t,i,n,r){var s,o,l,m,a,u;if(m=e.length,d("Collection length: %d",m),0===m)return d("Finished processing a collection."),r(null,t);for(l=m0&&c();function c(){function r(e,i){if(!o){if(e)return o=!0,p(e);d("Accumulator: %s",JSON.stringify(i)),t=i,p()}}d("Collection element %d: %s.",a-=1,JSON.stringify(e[a])),3===n.length?n.call(i.thisArg,t,e[a],r):4===n.length?n.call(i.thisArg,t,e[a],a,r):n.call(i.thisArg,t,e[a],a,e,r)}function p(e){return e?(d("Encountered an error: %s",e.message),r(e)):(d("Processed %d of %d collection elements.",s+=1,m),a>0?c():s===m?(d("Finished processing a collection."),r(null,t)):void 0)}}function p(e,s){var o,l,m;if(o={},arguments.length>1){if(l=a(o,e))throw l;m=s}else m=e;if(!t(m))throw new TypeError(n("invalid argument. Last argument must be a function. Value: `%s`.",m));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=r),u;function u(e,r,s){if(!i(e))throw new TypeError(n("invalid argument. First argument must be a collection. Value: `%s`.",e));if(!t(s))throw new TypeError(n("invalid argument. Last argument must be a function. Value: `%s`.",s));return c(e,r,o,m,(function(e,t){if(e)return s(e);s(null,t)}))}}function f(e,t,i,n,r){if(arguments.length<5)return p(i)(e,t,n);p(i,n)(e,t,r)}e(f,"factory",p);export{f as default,p as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..42fb408 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@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\nexport default 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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/string-format';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\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 === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, 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 ( !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, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","logger","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly","main"],"mappings":";;+4BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,+DAAgE,SAAUR,EAAKK,SAG1GF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,wEAAyE,QAASR,EAAKS,QAGhH,MAjBC,IAAIF,UAAWC,EAAQ,qEAAsEP,GAkBtG,8eC/CIU,uDAAQC,CAAQ,4BAkBpB,SAASH,EAAOI,EAAYC,EAAKd,EAAMe,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMP,EAAWU,OACjBZ,EAAO,wBAAyBS,GAEnB,IAARA,EAEJ,OADAT,EAAO,qCACAK,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAEZE,EAAO,wBAAyBQ,GAChCR,EAAO,0BAA2BI,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdf,EAAO,kBAAmBkB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,GAPC,CAQD,CA5BDjB,EAAO,6BADPU,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJf,EAAO,2BAA4Be,EAAMM,SAClChB,EAAMU,KAGdf,EAAO,0CADPM,GAAS,EACgDG,GACpDC,EAAM,EACHG,IAEHP,IAAUG,GACdT,EAAO,qCACAK,EAAM,KAAMF,SAFpB,EAIA,CACF,CCzCA,SAASmB,EAAShC,EAASc,GAC1B,IAAIf,EACAkC,EACAC,EAGJ,GADAnC,EAAO,CAAA,EACFoC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMnC,EAAUC,EAAMC,GAErB,MAAMiC,EAEPC,EAAIpB,CACN,MACEoB,EAAIlC,EAEL,IAAMoC,EAAYF,GACjB,MAAM,IAAI5B,UAAWC,EAAQ,mEAAoE2B,IAUlG,YARqB,IAAhBnC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ6B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIN,UAAWC,EAAQ,sEAAuEK,IAErG,IAAMwB,EAAYrB,GACjB,MAAM,IAAIT,UAAWC,EAAQ,mEAAoEQ,IAElG,OAAOP,EAAOI,EAAY2B,EAASxC,EAAMmC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,EACZ,GACD,CACF,CC1EA,SAASyB,EAAkB1B,EAAY2B,EAASvC,EAASc,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAShC,EAATgC,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAShC,EAASc,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,EAC/C,CClBA0B,EAAAC,EAAA,UAAAV"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 1125052..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,164 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/string-format' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var validate = require( './validate.js' ); -var limit = require( './limit.js' ); - - -// MAIN // - -/** -* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} last argument must be a function -* @returns {Function} function which invokes the provided function once for each element in a collection -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error, data ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var opts = { -* 'series': false -* }; -* -* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: -* var reduceRightAsync = factory( opts, read ); -* -* // Create a collection over which to iterate: -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* // Define a callback which handles errors: -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* // Run `read` for each element in `files`: -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, done ); -*/ -function factory( options, fcn ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = fcn; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); - } - if ( opts.series === void 0 && opts.limit === void 0 ) { - opts.series = true; - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return reduceRightAsync; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * @private - * @param {Collection} collection - input collection - * @param {*} initial - initial value - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be a collection - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function reduceRightAsync( collection, initial, done ) { - if ( !isCollection( collection ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a collection. Value: `%s`.', collection ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); - } - return limit( collection, initial, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {*} [acc] - accumulated value - * @returns {void} - */ - function clbk( error, acc ) { - if ( error ) { - return done( error ); - } - done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ae657ff..0000000 --- a/lib/index.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* @module @stdlib/utils-async-reduce-right -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' ); -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/limit.js b/lib/limit.js deleted file mode 100644 index cdb60af..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); - - -// VARIABLES // - -var debug = logger( 'reduce-right-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each element in a collection, limiting the number of concurrently pending functions and iterating from right to left. -* -* @private -* @param {Collection} collection - input collection -* @param {*} acc - initial value -* @param {Options} opts - function options -* @param {*} [opts.thisArg] - execution context -* @param {PositiveInteger} [opts.limit] - maximum number of pending function invocations -* @param {Function} fcn - function to invoke -* @param {Callback} done - function to invoke upon completion or upon encountering an error -* @returns {void} -*/ -function limit( collection, acc, opts, fcn, done ) { - var count; - var flg; - var lim; - var len; - var idx; - var i; - - len = collection.length; - debug( 'Collection length: %d', len ); - - if ( len === 0 ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - count = 0; - idx = len; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all collection elements... - if ( idx > 0 ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next element in a collection. - * - * @private - */ - function next() { - idx -= 1; - debug( 'Collection element %d: %s.', idx, JSON.stringify( collection[ idx ] ) ); - if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], cb ); - } else if ( fcn.length === 4 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, cb ); - } else { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len - } - /** - * Callback invoked once a provided function finishes processing a collection element. - * - * @private - * @param {*} [error] - error - * @param {*} [result] - accumulation result - * @returns {void} - */ - function cb( error, result ) { - if ( flg ) { - // Prevent further processing of collection elements: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Accumulator: %s', JSON.stringify( result ) ); - acc = result; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next collection element. - * - * @private - * @param {*} [error] - error - * @returns {void} - */ - function clbk( error ) { - if ( error ) { - debug( 'Encountered an error: %s', error.message ); - return done( error ); - } - count += 1; - debug( 'Processed %d of %d collection elements.', count, len ); - if ( idx > 0 ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index c8b0d0f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param {Collection} collection - input collection -* @param {*} initial - initial value -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} second-to-last argument must be a function -* @throws {TypeError} last argument must be a function -* @returns {void} -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -function reduceRightAsync( collection, initial, options, fcn, done ) { - if ( arguments.length < 5 ) { - return factory( options )( collection, initial, fcn ); - } - factory( options, fcn )( collection, initial, done ); -} - - -// EXPORTS // - -module.exports = reduceRightAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 9ba927e..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @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 -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'thisArg': {}, -* 'series': false, -* 'limit': 10 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp( options, 'thisArg' ) ) { - opts.thisArg = options.thisArg; - } - if ( hasOwnProp( options, 'series' ) ) { - opts.series = options.series; - if ( !isBoolean( opts.series ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index a3e4906..d4f9525 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,43 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-boolean": "^0.1.1", - "@stdlib/assert-is-collection": "^0.1.0", - "@stdlib/assert-is-function": "^0.1.1", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/assert-is-positive-integer": "^0.1.0", - "@stdlib/constants-float64-pinf": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.2.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/constants-float64-eps": "^0.1.1", - "@stdlib/fs-read-file": "^0.1.1", - "@stdlib/utils-noop": "^0.1.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.1.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..6fc8584 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 8244931..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1095 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( {}, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, next ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - factory( opts, next ); - }; - } -}); - -tape( 'the function returns a function (no options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided a collection (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a collection (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (1 argument)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (2 arguments)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with five arguments', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn() { - var value; - var next; - var acc; - var k; - - acc = arguments[ 0 ]; - value = arguments[ 1 ]; - k = arguments[ 2 ]; - next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( k, i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the returned function supports processing collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements concurrently', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 100, 250, 300 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements sequentially (limit = 1)', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of collection elements which are processed at any one time', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 250, 300, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 250, 100, 300 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var reduceRightAsync; - var arr; - - reduceRightAsync = factory( fcn ); - arr = []; - - reduceRightAsync( arr, 0, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var reduceRightAsync; - var obj; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = []; - obj = {}; - reduceRightAsync( arr, obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - i = 0; - - reduceRightAsync( arr, {}, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, acc ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the returned function does not skip empty elements', function test( t ) { - var reduceRightAsync; - var expected; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index f273a40..0000000 --- a/test/test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof reduceRightAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 1893240..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1035 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a collection', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (no options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, next, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, 0 ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - reduceRightAsync( [ 1, 2, 3 ], 0, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (1 argument)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (2 arguments)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with five arguments', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn() { - var next; - var acc; - var v; - - next = arguments[ 4 ]; - acc = arguments[ 0 ]; - v = arguments[ 1 ]; - - i -= 1; - j += 1; - - t.strictEqual( v, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, v ); - - function onTimeout() { - acc.sum += v; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'by default, the function processes collection elements sequentially', function test( t ) { - var values; - var count; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements concurrently', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 100, 250, 300 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': true - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially (limit = 1)', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var arr; - var ctx; - - arr = [ 3, 2, 1 ]; - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 3, 2, 1 ]; - opts = { - 'series': true - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 250, 100, 300 ]; - opts = { - 'limit': 2 - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var arr = []; - reduceRightAsync( arr, 0, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var arr = []; - var obj = {}; - - reduceRightAsync( arr, obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - arr = [ 3, 2, 1 ]; - i = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, value ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the function does not skip empty elements', function test( t ) { - var expected; - var arr; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, fcn, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 7660838..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,181 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `limit` option which is not a positive integer', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - -5, - 0, - 3.14, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'limit': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `series` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'series': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function accepts any value for the `thisArg` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'thisArg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err, null, 'returns null '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'thisArg': {}, - 'series': false, - 'limit': 10 - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From cbed5f8299001a72665aa342578a888b8bb4c25a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 08:39:39 +0000 Subject: [PATCH 094/147] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1613d90..d2c8704 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-plain-object": "^0.2.0", "@stdlib/assert-is-positive-integer": "^0.2.0", "@stdlib/constants-float64-pinf": "^0.2.0", - "@stdlib/string-format": "^0.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.2.0", "@stdlib/types": "^0.3.1", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.0", "debug": "^2.6.9" From 458cca66db799e80052eabf009b086ff419a283c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 17:16:00 +0000 Subject: [PATCH 095/147] Remove files --- index.d.ts | 410 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6592 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index f6cba5d..0000000 --- a/index.d.ts +++ /dev/null @@ -1,410 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Execution context. - */ - thisArg?: ThisParameterType>; - - /** - * The maximum number of pending invocations at any one time. - */ - limit?: number; - - /** - * Boolean indicating whether to sequentially invoke the reducer function for each `collection` element. If `true`, the function sets `options.limit=1`. Default: true. - */ - series?: boolean; -} - -/** -* Callback function. -*/ -type Nullary = () => void; - -/** -* Callback function. -* -* @param error - encountered error or null -*/ -type Unary = ( error: Error | null ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Binary = ( error: Error | null, accumulator: U ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param next - a callback to be invoked after processing a collection `value` -*/ -type TernaryReducer = ( this: V, accumulator: U, value: T, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuaternaryReducer = ( this: V, accumulator: U, value: T, index: number, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuinaryReducer = ( this: V, accumulator: U, value: T, index: number, collection: Collection, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type Reducer = TernaryReducer | QuaternaryReducer | QuinaryReducer; - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result. -* -* @param collection - input collection -* @param initial - initial value -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( collection: Collection, initial: U, done: Callback ) => void; - -/** -* Interface for `reduceRightAsync`. -*/ -interface ReduceRightAsync { - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, {}, read, done ); - */ - ( collection: Collection, initial: U, options: Options, reducer: Reducer, done: Callback ): void; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, read, done ); - */ - ( collection: Collection, initial: U, reducer: Reducer, done: Callback ): void; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @throws must provide valid options - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var opts = { - * 'series': false - * }; - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( opts, read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( options: Options, reducer: Reducer ): FactoryFunction; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param reducer - function to invoke for each element in a collection - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( reducer: Reducer ): FactoryFunction; -} - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param collection - input collection -* @param initial - initial value -* @param options - function options -* @param options.thisArg - execution context -* @param options.limit - maximum number of pending invocations at any one time -* @param 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 (default: true) -* @param reducer - function to invoke for each element in a collection -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -declare var reduceRightAsync: ReduceRightAsync; - - -// EXPORTS // - -export = reduceRightAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 48ff8e2..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import{isPrimitive as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.1.0-esm/index.mjs";function a(e,t){return s(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(n("invalid option. `%s` option must be a boolean. Option: `%s`.","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!m(e.limit))?new TypeError(n("invalid option. `%s` option must be a positive integer. Option: `%s`.","limit",e.limit)):null):new TypeError(n("invalid argument. Options argument must be an object. Value: `%s`.",t))}function u(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){if(this instanceof e){var i=[null];i.push.apply(i,arguments);var n=Function.bind.apply(t,i);return new n}return t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})})),i}var d=u(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function c(e,t,i,n,r){var s,o,l,m,a,u;if(m=e.length,d("Collection length: %d",m),0===m)return d("Finished processing a collection."),r(null,t);for(l=m0&&c();function c(){function r(e,i){if(!o){if(e)return o=!0,p(e);d("Accumulator: %s",JSON.stringify(i)),t=i,p()}}d("Collection element %d: %s.",a-=1,JSON.stringify(e[a])),3===n.length?n.call(i.thisArg,t,e[a],r):4===n.length?n.call(i.thisArg,t,e[a],a,r):n.call(i.thisArg,t,e[a],a,e,r)}function p(e){return e?(d("Encountered an error: %s",e.message),r(e)):(d("Processed %d of %d collection elements.",s+=1,m),a>0?c():s===m?(d("Finished processing a collection."),r(null,t)):void 0)}}function p(e,s){var o,l,m;if(o={},arguments.length>1){if(l=a(o,e))throw l;m=s}else m=e;if(!t(m))throw new TypeError(n("invalid argument. Last argument must be a function. Value: `%s`.",m));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=r),u;function u(e,r,s){if(!i(e))throw new TypeError(n("invalid argument. First argument must be a collection. Value: `%s`.",e));if(!t(s))throw new TypeError(n("invalid argument. Last argument must be a function. Value: `%s`.",s));return c(e,r,o,m,(function(e,t){if(e)return s(e);s(null,t)}))}}function f(e,t,i,n,r){if(arguments.length<5)return p(i)(e,t,n);p(i,n)(e,t,r)}e(f,"factory",p);export{f as default,p as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 42fb408..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@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\nexport default 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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/string-format';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\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 === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, 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 ( !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, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","logger","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly","main"],"mappings":";;+4BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,+DAAgE,SAAUR,EAAKK,SAG1GF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,wEAAyE,QAASR,EAAKS,QAGhH,MAjBC,IAAIF,UAAWC,EAAQ,qEAAsEP,GAkBtG,8eC/CIU,uDAAQC,CAAQ,4BAkBpB,SAASH,EAAOI,EAAYC,EAAKd,EAAMe,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMP,EAAWU,OACjBZ,EAAO,wBAAyBS,GAEnB,IAARA,EAEJ,OADAT,EAAO,qCACAK,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAEZE,EAAO,wBAAyBQ,GAChCR,EAAO,0BAA2BI,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdf,EAAO,kBAAmBkB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,GAPC,CAQD,CA5BDjB,EAAO,6BADPU,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJf,EAAO,2BAA4Be,EAAMM,SAClChB,EAAMU,KAGdf,EAAO,0CADPM,GAAS,EACgDG,GACpDC,EAAM,EACHG,IAEHP,IAAUG,GACdT,EAAO,qCACAK,EAAM,KAAMF,SAFpB,EAIA,CACF,CCzCA,SAASmB,EAAShC,EAASc,GAC1B,IAAIf,EACAkC,EACAC,EAGJ,GADAnC,EAAO,CAAA,EACFoC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMnC,EAAUC,EAAMC,GAErB,MAAMiC,EAEPC,EAAIpB,CACN,MACEoB,EAAIlC,EAEL,IAAMoC,EAAYF,GACjB,MAAM,IAAI5B,UAAWC,EAAQ,mEAAoE2B,IAUlG,YARqB,IAAhBnC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ6B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIN,UAAWC,EAAQ,sEAAuEK,IAErG,IAAMwB,EAAYrB,GACjB,MAAM,IAAIT,UAAWC,EAAQ,mEAAoEQ,IAElG,OAAOP,EAAOI,EAAY2B,EAASxC,EAAMmC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,EACZ,GACD,CACF,CC1EA,SAASyB,EAAkB1B,EAAY2B,EAASvC,EAASc,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAShC,EAATgC,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAShC,EAASc,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,EAC/C,CClBA0B,EAAAC,EAAA,UAAAV"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 6fc8584..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 6122fced38c06db1bb7fc09b77c2782905c7bddf Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 17:16:18 +0000 Subject: [PATCH 096/147] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 132 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.factory.js | 73 - benchmark/benchmark.js | 160 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 224 - docs/types/test.ts | 166 - examples/index.js | 55 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 164 - lib/index.js | 77 - lib/limit.js | 142 - lib/main.js | 95 - lib/validate.js | 80 - package.json | 64 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 1095 ---- test/test.js | 38 - test/test.main.js | 1035 ---- test/test.validate.js | 181 - 49 files changed, 6208 insertions(+), 6956 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/limit.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1e08946..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 5358060..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 02d3957..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '37 1 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9106b5d..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -460,7 +457,7 @@ reduceRightAsync( files, acc, read, done ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -531,11 +528,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right +[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right/tree/esm -[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce +[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index b155fd2..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var reduceRightAsync; - var arr; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - reduceRightAsync = factory( onItem ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - var acc; - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index af5c346..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var reduceRightAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=false', function benchmark( b ) { - var opts; - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'series': false - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var arr; - var len; - var acc; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'limit': 3 - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b8adcd2..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right" -%% click B href "https://github.com/stdlib-js/utils-async-reduce-right/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-reduce-right/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-reduce-right/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-reduce-right/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right -[production-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-async-reduce-right/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-async-reduce-right/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-async-reduce-right/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 47a072e..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import reduceRightAsync from '../docs/types/index'; -export = reduceRightAsync; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 530ca4d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var c=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var x=c(function(U,O){ -var R=require('@stdlib/assert-is-plain-object/dist'),h=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,k=require('@stdlib/assert-is-positive-integer/dist').isPrimitive,d=require('@stdlib/error-tools-fmtprodmsg/dist');function I(e,r){return R(r)?(h(r,"thisArg")&&(e.thisArg=r.thisArg),h(r,"series")&&(e.series=r.series,!j(e.series))?new TypeError(d('1RZ2o',"series",e.series)):h(r,"limit")&&(e.limit=r.limit,!k(e.limit))?new TypeError(d('1RZ3P',"limit",e.limit)):null):new TypeError(d('1RZ2V',r));}O.exports=I -});var P=c(function(W,E){ -var J=require("debug"),a=J("reduce-right-async:limit");function L(e,r,i,t,s){var f,m,v,n,u,g;if(n=e.length,a("Collection length: %d",n),n===0)return a("Finished processing a collection."),s(null,r);for(n0&&o();function o(){u-=1,a("Collection element %d: %s.",u,JSON.stringify(e[u])),t.length===3?t.call(i.thisArg,r,e[u],l):t.length===4?t.call(i.thisArg,r,e[u],u,l):t.call(i.thisArg,r,e[u],u,e,l);function l(w,A){if(!m){if(w)return m=!0,b(w);a("Accumulator: %s",JSON.stringify(A)),r=A,b()}}}function b(l){if(l)return a("Encountered an error: %s",l.message),s(l);if(f+=1,a("Processed %d of %d collection elements.",f,n),u>0)return o();if(f===n)return a("Finished processing a collection."),s(null,r)}}E.exports=L -});var q=c(function(X,F){ -var T=require('@stdlib/assert-is-function/dist'),S=require('@stdlib/assert-is-collection/dist'),y=require('@stdlib/error-tools-fmtprodmsg/dist'),B=require('@stdlib/constants-float64-pinf/dist'),z=x(),D=P();function G(e,r){var i,t,s;if(i={},arguments.length>1){if(t=z(i,e),t)throw t;s=r}else s=e;if(!T(s))throw new TypeError(y('1RZ3q',s));return i.series===void 0&&i.limit===void 0&&(i.series=!0),i.series?i.limit=1:i.limit||(i.limit=B),f;function f(m,v,n){if(!S(m))throw new TypeError(y('1RZAh',m));if(!T(n))throw new TypeError(y('1RZ3q',n));return D(m,v,i,s,u);function u(g,o){if(g)return n(g);n(null,o)}}}F.exports=G -});var N=c(function(Y,C){ -var p=q();function H(e,r,i,t,s){if(arguments.length<5)return p(i)(e,r,t);p(i,t)(e,r,s)}C.exports=H -});var K=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),V=N(),M=q();K(V,"factory",M);module.exports=V; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index acb9d67..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/limit.js", "../lib/factory.js", "../lib/main.js", "../lib/index.js"], - "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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\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 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 to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\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 === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, 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 ( !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, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\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* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nmodule.exports = reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' );\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, 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"], - "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,0BAA2B,EAkB/C,SAASE,EAAOC,EAAYC,EAAKC,EAAMC,EAAKC,EAAO,CAClD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMR,EAAW,OACjBF,EAAO,wBAAyBU,CAAI,EAE/BA,IAAQ,EACZ,OAAAV,EAAO,mCAAoC,EACpCM,EAAM,KAAMH,CAAI,EAYxB,IAVKO,EAAMN,EAAK,MACfK,EAAMC,EAEND,EAAML,EAAK,MAEZJ,EAAO,wBAAyBS,CAAI,EACpCT,EAAO,0BAA2BK,EAAI,MAAO,EAE7CE,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVE,EAAK,EAQP,SAASA,GAAO,CACfF,GAAO,EACPX,EAAO,6BAA8BW,EAAK,KAAK,UAAWT,EAAYS,CAAI,CAAE,CAAE,EACzEN,EAAI,SAAW,EACnBA,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGG,CAAG,EACxCT,EAAI,SAAW,EAC1BA,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGA,EAAKG,CAAG,EAExDT,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGA,EAAKT,EAAYY,CAAG,EAUrE,SAASA,EAAIC,EAAOC,EAAS,CAC5B,GAAK,CAAAR,EAIL,IAAKO,EACJ,OAAAP,EAAM,GACCS,EAAMF,CAAM,EAEpBf,EAAO,kBAAmB,KAAK,UAAWgB,CAAO,CAAE,EACnDb,EAAMa,EACNC,EAAK,EACN,CACD,CASA,SAASA,EAAMF,EAAQ,CACtB,GAAKA,EACJ,OAAAf,EAAO,2BAA4Be,EAAM,OAAQ,EAC1CT,EAAMS,CAAM,EAIpB,GAFAR,GAAS,EACTP,EAAO,0CAA2CO,EAAOG,CAAI,EACxDC,EAAM,EACV,OAAOE,EAAK,EAEb,GAAKN,IAAUG,EACd,OAAAV,EAAO,mCAAoC,EACpCM,EAAM,KAAMH,CAAI,CAEzB,CACD,CAKAL,EAAO,QAAUG,IC7IjB,IAAAiB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,gCAAiC,EACjDC,EAAW,IACXC,EAAQ,IAoEZ,SAASC,EAASC,EAASC,EAAM,CAChC,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,CAACP,EAAYW,CAAE,EACnB,MAAM,IAAI,UAAWT,EAAQ,mEAAoES,CAAE,CAAE,EAEtG,OAAKF,EAAK,SAAW,QAAUA,EAAK,QAAU,SAC7CA,EAAK,OAAS,IAEVA,EAAK,OACTA,EAAK,MAAQ,EACDA,EAAK,QACjBA,EAAK,MAAQN,GAEPS,EAaP,SAASA,EAAkBC,EAAYC,EAASC,EAAO,CACtD,GAAK,CAACd,EAAcY,CAAW,EAC9B,MAAM,IAAI,UAAWX,EAAQ,sEAAuEW,CAAW,CAAE,EAElH,GAAK,CAACb,EAAYe,CAAK,EACtB,MAAM,IAAI,UAAWb,EAAQ,mEAAoEa,CAAK,CAAE,EAEzG,OAAOV,EAAOQ,EAAYC,EAASL,EAAME,EAAGK,CAAK,EAUjD,SAASA,EAAMC,EAAOC,EAAM,CAC3B,GAAKD,EACJ,OAAOF,EAAME,CAAM,EAEpBF,EAAM,KAAMG,CAAI,CACjB,CACD,CACD,CAKAnB,EAAO,QAAUO,ICnKjB,IAAAa,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,IA8Dd,SAASC,EAAkBC,EAAYC,EAASC,EAASC,EAAKC,EAAO,CACpE,GAAK,UAAU,OAAS,EACvB,OAAON,EAASI,CAAQ,EAAGF,EAAYC,EAASE,CAAI,EAErDL,EAASI,EAASC,CAAI,EAAGH,EAAYC,EAASG,CAAK,CACpD,CAKAP,EAAO,QAAUE,IC9BjB,IAAIM,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "isPositiveInteger", "format", "validate", "opts", "options", "require_limit", "__commonJSMin", "exports", "module", "logger", "debug", "limit", "collection", "acc", "opts", "fcn", "done", "count", "flg", "lim", "len", "idx", "i", "next", "cb", "error", "result", "clbk", "require_factory", "__commonJSMin", "exports", "module", "isFunction", "isCollection", "format", "PINF", "validate", "limit", "factory", "options", "fcn", "opts", "err", "f", "reduceRightAsync", "collection", "initial", "done", "clbk", "error", "acc", "require_main", "__commonJSMin", "exports", "module", "factory", "reduceRightAsync", "collection", "initial", "options", "fcn", "done", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3f22669..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,224 +0,0 @@ - -{{alias}}( collection, initial, [options,] reducer, done ) - Applies a function against an accumulator and each element in a collection - and returns the accumulated result, iterating from right to left. - - When invoked, `reducer` is provided a maximum of five arguments: - - - `accumulator`: accumulated value - - `value`: collection value - - `index`: collection index - - `collection`: the input collection - - `next`: a callback to be invoked after processing a collection `value` - - The actual number of provided arguments depends on function length. If - `reducer` accepts three arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `next` - - If `reducer` accepts four arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `index` - - `next` - - For every other `reducer` signature, `reducer` is provided all five - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `accumulator`: accumulated value - - If a provided function calls the `next` callback with a truthy `error` - argument, the function suspends execution and immediately calls the `done` - callback for subsequent `error` handling. - - Execution is *not* guaranteed to be asynchronous. To guarantee asynchrony, - 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`). - - The function does not support dynamic collection resizing. - - If provided an empty collection, the function invokes the `done` callback - with the `initial` value as the second argument. - - The function does not skip `undefined` elements. - - When processing collection elements concurrently, *beware* of race - conditions when updating an accumulator. This is especially true when an - accumulator is a primitive (e.g., a number). In general, prefer object - accumulators. - - Parameters - ---------- - collection: Array|TypedArray|Object - Input collection over which to iterate. If provided an object, the - object must be array-like (excluding strings and functions). - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - reducer: Function - The function to invoke for each element in a collection. - - done: Function - A callback invoked either upon processing all collection elements or - upon encountering an error. - - Examples - -------- - // Basic usage: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, fcn, done ) - 3000 - 2500 - 1000 - 6500 - - // Limit number of concurrent invocations: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'limit': 2 }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 2500 - 3000 - 1000 - 6500 - - // Process concurrently: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'series': false }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 1000 - 2500 - 3000 - 6500 - - -{{alias}}.factory( [options,] fcn ) - Returns a function which applies a function against an accumulator and each - element in a collection and returns the accumulated result, iterating from - right to left. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - fcn: Function - The function to invoke for each element in a collection. - - Returns - ------- - out: Function - A function which invokes a function for each element in a collection. - - Examples - -------- - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > var opts = { 'series': false }; - > var f = {{alias}}.factory( opts, fcn ); - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > f( arr, acc, done ) - 1000 - 2500 - 3000 - 6500 - > acc = { 'sum': 0 }; - > arr = [ 1000, 1500, 2000 ]; - > f( arr, acc, done ) - 1000 - 1500 - 2000 - 4500 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0455864..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,166 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unsafe-assignment */ - -import reduceRightAsync = require( './index' ); - -const reducer = ( acc: any, value: number, index: number, next: Function ) => { - acc.sum += value; - if ( index === void 0 ) { - throw new Error( '`index` is missing.' ); - } - next( null, acc ); -}; - -const done = ( error: Error | null, acc: any ) => { - if ( error ) { - throw error; - } - if ( acc === void 0 ) { - throw new Error( '`acc` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( 2, acc, reducer, done ); // $ExpectError - reduceRightAsync( false, acc, reducer, done ); // $ExpectError - reduceRightAsync( true, acc, reducer, done ); // $ExpectError - reduceRightAsync( {}, acc, reducer, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a predicate argument which is not a predicate function... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 2, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, false, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, true, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 'abc', done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, [], done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a done callback argument which is not a function having a supported signature... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 2 ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, false ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, true ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 'abc' ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, {} ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, [] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const acc = { 'sum': 0 }; - reduceRightAsync(); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, reducer, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - reduceRightAsync.factory( reducer ); // $ExpectType FactoryFunction - reduceRightAsync.factory( { 'series': true }, reducer ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - reduceRightAsync.factory( [], reducer ); // $ExpectError - reduceRightAsync.factory( 123, reducer ); // $ExpectError - reduceRightAsync.factory( 'abc', reducer ); // $ExpectError - reduceRightAsync.factory( false, reducer ); // $ExpectError - reduceRightAsync.factory( true, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not a predicate function... -{ - reduceRightAsync.factory( {} ); // $ExpectError - reduceRightAsync.factory( true ); // $ExpectError - reduceRightAsync.factory( false ); // $ExpectError - reduceRightAsync.factory( {}, 123 ); // $ExpectError - reduceRightAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1( 12, acc, done ); // $ExpectError - fcn1( true, acc, done ); // $ExpectError - fcn1( false, acc, done ); // $ExpectError - fcn1( {}, acc, done ); // $ExpectError - - fcn1( [ 3000, 2500, 1000 ], acc, 12 ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, true ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, false ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, '5' ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, {} ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, [] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1(); // $ExpectError - fcn1( [ 3000, 2500, 1000 ] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - reduceRightAsync.factory( { 'limit': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': true }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': false }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - reduceRightAsync.factory( { 'series': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': 12 }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - reduceRightAsync.factory(); // $ExpectError - reduceRightAsync.factory( {}, reducer, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index dd64345..0000000 --- a/examples/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var resolve = require( 'path' ).resolve; -var readFile = require( '@stdlib/fs-read-file' ); -var reduceRightAsync = require( './../lib' ); - -var files = [ - resolve( __dirname, '..', 'package.json' ), - resolve( __dirname, '..', 'README.md' ) -]; - -function done( error, acc ) { - if ( error ) { - throw error; - } - console.log( acc.count ); -} - -function read( acc, file, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( file, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( null, acc ); - } - acc.count += 1; - next( null, acc ); - } -} - -var acc = { - 'count': 0 -}; -reduceRightAsync( files, acc, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 28e0a36..f6cba5d 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..be882ad --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.0-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.0-esm/index.mjs";import{isPrimitive as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.1.0-esm/index.mjs";function a(e,t){return s(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(n("invalid option. `%s` option must be a boolean. Option: `%s`.","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!m(e.limit))?new TypeError(n("invalid option. `%s` option must be a positive integer. Option: `%s`.","limit",e.limit)):null):new TypeError(n("invalid argument. Options argument must be an object. Value: `%s`.",t))}function u(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){if(this instanceof e){var i=[null];i.push.apply(i,arguments);var n=Function.bind.apply(t,i);return new n}return t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})})),i}var d=u(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function c(e,t,i,n,r){var s,o,l,m,a,u;if(m=e.length,d("Collection length: %d",m),0===m)return d("Finished processing a collection."),r(null,t);for(l=m0&&c();function c(){function r(e,i){if(!o){if(e)return o=!0,p(e);d("Accumulator: %s",JSON.stringify(i)),t=i,p()}}d("Collection element %d: %s.",a-=1,JSON.stringify(e[a])),3===n.length?n.call(i.thisArg,t,e[a],r):4===n.length?n.call(i.thisArg,t,e[a],a,r):n.call(i.thisArg,t,e[a],a,e,r)}function p(e){return e?(d("Encountered an error: %s",e.message),r(e)):(d("Processed %d of %d collection elements.",s+=1,m),a>0?c():s===m?(d("Finished processing a collection."),r(null,t)):void 0)}}function p(e,s){var o,l,m;if(o={},arguments.length>1){if(l=a(o,e))throw l;m=s}else m=e;if(!t(m))throw new TypeError(n("invalid argument. Last argument must be a function. Value: `%s`.",m));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=r),u;function u(e,r,s){if(!i(e))throw new TypeError(n("invalid argument. First argument must be a collection. Value: `%s`.",e));if(!t(s))throw new TypeError(n("invalid argument. Last argument must be a function. Value: `%s`.",s));return c(e,r,o,m,(function(e,t){if(e)return s(e);s(null,t)}))}}function f(e,t,i,n,r){if(arguments.length<5)return p(i)(e,t,n);p(i,n)(e,t,r)}e(f,"factory",p);export{f as default,p as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..42fb408 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@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\nexport default 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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/string-format';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\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 === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, 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 ( !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, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","logger","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly","main"],"mappings":";;+4BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,+DAAgE,SAAUR,EAAKK,SAG1GF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,wEAAyE,QAASR,EAAKS,QAGhH,MAjBC,IAAIF,UAAWC,EAAQ,qEAAsEP,GAkBtG,8eC/CIU,uDAAQC,CAAQ,4BAkBpB,SAASH,EAAOI,EAAYC,EAAKd,EAAMe,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMP,EAAWU,OACjBZ,EAAO,wBAAyBS,GAEnB,IAARA,EAEJ,OADAT,EAAO,qCACAK,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAEZE,EAAO,wBAAyBQ,GAChCR,EAAO,0BAA2BI,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdf,EAAO,kBAAmBkB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,GAPC,CAQD,CA5BDjB,EAAO,6BADPU,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJf,EAAO,2BAA4Be,EAAMM,SAClChB,EAAMU,KAGdf,EAAO,0CADPM,GAAS,EACgDG,GACpDC,EAAM,EACHG,IAEHP,IAAUG,GACdT,EAAO,qCACAK,EAAM,KAAMF,SAFpB,EAIA,CACF,CCzCA,SAASmB,EAAShC,EAASc,GAC1B,IAAIf,EACAkC,EACAC,EAGJ,GADAnC,EAAO,CAAA,EACFoC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMnC,EAAUC,EAAMC,GAErB,MAAMiC,EAEPC,EAAIpB,CACN,MACEoB,EAAIlC,EAEL,IAAMoC,EAAYF,GACjB,MAAM,IAAI5B,UAAWC,EAAQ,mEAAoE2B,IAUlG,YARqB,IAAhBnC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ6B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIN,UAAWC,EAAQ,sEAAuEK,IAErG,IAAMwB,EAAYrB,GACjB,MAAM,IAAIT,UAAWC,EAAQ,mEAAoEQ,IAElG,OAAOP,EAAOI,EAAY2B,EAASxC,EAAMmC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,EACZ,GACD,CACF,CC1EA,SAASyB,EAAkB1B,EAAY2B,EAASvC,EAASc,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAShC,EAATgC,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAShC,EAASc,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,EAC/C,CClBA0B,EAAAC,EAAA,UAAAV"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 1125052..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,164 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/string-format' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var validate = require( './validate.js' ); -var limit = require( './limit.js' ); - - -// MAIN // - -/** -* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} last argument must be a function -* @returns {Function} function which invokes the provided function once for each element in a collection -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error, data ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var opts = { -* 'series': false -* }; -* -* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: -* var reduceRightAsync = factory( opts, read ); -* -* // Create a collection over which to iterate: -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* // Define a callback which handles errors: -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* // Run `read` for each element in `files`: -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, done ); -*/ -function factory( options, fcn ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = fcn; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); - } - if ( opts.series === void 0 && opts.limit === void 0 ) { - opts.series = true; - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return reduceRightAsync; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * @private - * @param {Collection} collection - input collection - * @param {*} initial - initial value - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be a collection - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function reduceRightAsync( collection, initial, done ) { - if ( !isCollection( collection ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a collection. Value: `%s`.', collection ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); - } - return limit( collection, initial, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {*} [acc] - accumulated value - * @returns {void} - */ - function clbk( error, acc ) { - if ( error ) { - return done( error ); - } - done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ae657ff..0000000 --- a/lib/index.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* @module @stdlib/utils-async-reduce-right -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' ); -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/limit.js b/lib/limit.js deleted file mode 100644 index cdb60af..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); - - -// VARIABLES // - -var debug = logger( 'reduce-right-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each element in a collection, limiting the number of concurrently pending functions and iterating from right to left. -* -* @private -* @param {Collection} collection - input collection -* @param {*} acc - initial value -* @param {Options} opts - function options -* @param {*} [opts.thisArg] - execution context -* @param {PositiveInteger} [opts.limit] - maximum number of pending function invocations -* @param {Function} fcn - function to invoke -* @param {Callback} done - function to invoke upon completion or upon encountering an error -* @returns {void} -*/ -function limit( collection, acc, opts, fcn, done ) { - var count; - var flg; - var lim; - var len; - var idx; - var i; - - len = collection.length; - debug( 'Collection length: %d', len ); - - if ( len === 0 ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - count = 0; - idx = len; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all collection elements... - if ( idx > 0 ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next element in a collection. - * - * @private - */ - function next() { - idx -= 1; - debug( 'Collection element %d: %s.', idx, JSON.stringify( collection[ idx ] ) ); - if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], cb ); - } else if ( fcn.length === 4 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, cb ); - } else { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len - } - /** - * Callback invoked once a provided function finishes processing a collection element. - * - * @private - * @param {*} [error] - error - * @param {*} [result] - accumulation result - * @returns {void} - */ - function cb( error, result ) { - if ( flg ) { - // Prevent further processing of collection elements: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Accumulator: %s', JSON.stringify( result ) ); - acc = result; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next collection element. - * - * @private - * @param {*} [error] - error - * @returns {void} - */ - function clbk( error ) { - if ( error ) { - debug( 'Encountered an error: %s', error.message ); - return done( error ); - } - count += 1; - debug( 'Processed %d of %d collection elements.', count, len ); - if ( idx > 0 ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index c8b0d0f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param {Collection} collection - input collection -* @param {*} initial - initial value -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} second-to-last argument must be a function -* @throws {TypeError} last argument must be a function -* @returns {void} -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -function reduceRightAsync( collection, initial, options, fcn, done ) { - if ( arguments.length < 5 ) { - return factory( options )( collection, initial, fcn ); - } - factory( options, fcn )( collection, initial, done ); -} - - -// EXPORTS // - -module.exports = reduceRightAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 9ba927e..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @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 -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'thisArg': {}, -* 'series': false, -* 'limit': 10 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp( options, 'thisArg' ) ) { - opts.thisArg = options.thisArg; - } - if ( hasOwnProp( options, 'series' ) ) { - opts.series = options.series; - if ( !isBoolean( opts.series ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index d2c8704..fd035b6 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.0", "description": "Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,43 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-boolean": "^0.2.0", - "@stdlib/assert-is-collection": "^0.2.0", - "@stdlib/assert-is-function": "^0.2.0", - "@stdlib/assert-is-plain-object": "^0.2.0", - "@stdlib/assert-is-positive-integer": "^0.2.0", - "@stdlib/constants-float64-pinf": "^0.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.0", - "@stdlib/types": "^0.3.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.0", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/constants-float64-eps": "^0.1.1", - "@stdlib/fs-read-file": "^0.1.1", - "@stdlib/utils-noop": "^0.2.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.1.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..4728e9e --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 8244931..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1095 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( {}, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, next ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - factory( opts, next ); - }; - } -}); - -tape( 'the function returns a function (no options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided a collection (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a collection (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (1 argument)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (2 arguments)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with five arguments', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn() { - var value; - var next; - var acc; - var k; - - acc = arguments[ 0 ]; - value = arguments[ 1 ]; - k = arguments[ 2 ]; - next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( k, i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the returned function supports processing collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements concurrently', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 100, 250, 300 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements sequentially (limit = 1)', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of collection elements which are processed at any one time', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 250, 300, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 250, 100, 300 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var reduceRightAsync; - var arr; - - reduceRightAsync = factory( fcn ); - arr = []; - - reduceRightAsync( arr, 0, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var reduceRightAsync; - var obj; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = []; - obj = {}; - reduceRightAsync( arr, obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - i = 0; - - reduceRightAsync( arr, {}, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, acc ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the returned function does not skip empty elements', function test( t ) { - var reduceRightAsync; - var expected; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index f273a40..0000000 --- a/test/test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof reduceRightAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 1893240..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1035 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a collection', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (no options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, next, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, 0 ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - reduceRightAsync( [ 1, 2, 3 ], 0, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (1 argument)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (2 arguments)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with five arguments', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn() { - var next; - var acc; - var v; - - next = arguments[ 4 ]; - acc = arguments[ 0 ]; - v = arguments[ 1 ]; - - i -= 1; - j += 1; - - t.strictEqual( v, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, v ); - - function onTimeout() { - acc.sum += v; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'by default, the function processes collection elements sequentially', function test( t ) { - var values; - var count; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements concurrently', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 100, 250, 300 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': true - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially (limit = 1)', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var arr; - var ctx; - - arr = [ 3, 2, 1 ]; - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 3, 2, 1 ]; - opts = { - 'series': true - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 250, 100, 300 ]; - opts = { - 'limit': 2 - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var arr = []; - reduceRightAsync( arr, 0, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var arr = []; - var obj = {}; - - reduceRightAsync( arr, obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - arr = [ 3, 2, 1 ]; - i = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, value ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the function does not skip empty elements', function test( t ) { - var expected; - var arr; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, fcn, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 7660838..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,181 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `limit` option which is not a positive integer', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - -5, - 0, - 3.14, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'limit': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `series` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'series': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function accepts any value for the `thisArg` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'thisArg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err, null, 'returns null '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'thisArg': {}, - 'series': false, - 'limit': 10 - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From a7b98a4e7b53d058ecd4f80c5a35815dae09656d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 20:30:03 +0000 Subject: [PATCH 097/147] Update README.md for ESM bundle v0.2.0 --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index bbe178e..95e9ee0 100644 --- a/README.md +++ b/README.md @@ -52,13 +52,13 @@ limitations under the License. ## Usage ```javascript -import reduceRightAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-reduce-right@esm/index.mjs'; +import reduceRightAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-reduce-right@v0.2.0-esm/index.mjs'; ``` You can also import the following named exports from the package: ```javascript -import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-reduce-right@esm/index.mjs'; +import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-reduce-right@v0.2.0-esm/index.mjs'; ``` #### reduceRightAsync( collection, initial, \[options,] reducer, done ) @@ -381,7 +381,7 @@ The function accepts the same `options` as `reduceRightAsync()`. var resolve = require( 'path' ).resolve; import readFile from 'https://cdn.jsdelivr.net/gh/stdlib-js/fs-read-file@esm/index.mjs'; -import reduceRightAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-reduce-right@esm/index.mjs'; +import reduceRightAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-reduce-right@v0.2.0-esm/index.mjs'; var files = [ resolve( __dirname, 'package.json' ), From 2a309596395c418db28c0526877f3e88d1e9fdbf Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 20:30:04 +0000 Subject: [PATCH 098/147] Auto-generated commit --- README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 95e9ee0..73a16c0 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import reduceRightAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-reduce-right@esm/index.mjs'; +``` +The previous example will load the latest bundled code from the esm branch. Alternatively, you may load a specific version by loading the file from one of the [tagged bundles](https://github.com/stdlib-js/utils-async-reduce-right/tags). For example, + ```javascript import reduceRightAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-reduce-right@v0.2.0-esm/index.mjs'; ``` @@ -58,7 +63,7 @@ import reduceRightAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async- You can also import the following named exports from the package: ```javascript -import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-reduce-right@v0.2.0-esm/index.mjs'; +import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-reduce-right@esm/index.mjs'; ``` #### reduceRightAsync( collection, initial, \[options,] reducer, done ) @@ -381,7 +386,7 @@ The function accepts the same `options` as `reduceRightAsync()`. var resolve = require( 'path' ).resolve; import readFile from 'https://cdn.jsdelivr.net/gh/stdlib-js/fs-read-file@esm/index.mjs'; -import reduceRightAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-reduce-right@v0.2.0-esm/index.mjs'; +import reduceRightAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-reduce-right@esm/index.mjs'; var files = [ resolve( __dirname, 'package.json' ), From a8ae51591a791d6884703be8bd83e2c705da39f3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 24 Feb 2024 16:08:50 +0000 Subject: [PATCH 099/147] Transform error messages --- lib/factory.js | 8 ++++---- lib/validate.js | 8 ++++---- package.json | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 1125052..e107128 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -22,7 +22,7 @@ var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var PINF = require( '@stdlib/constants-float64-pinf' ); var validate = require( './validate.js' ); var limit = require( './limit.js' ); @@ -109,7 +109,7 @@ function factory( options, fcn ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '1RZ3q', f ) ); } if ( opts.series === void 0 && opts.limit === void 0 ) { opts.series = true; @@ -134,10 +134,10 @@ function factory( options, fcn ) { */ function reduceRightAsync( collection, initial, done ) { if ( !isCollection( collection ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a collection. Value: `%s`.', collection ) ); + throw new TypeError( format( '1RZAh', collection ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '1RZ3q', done ) ); } return limit( collection, initial, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index 9ba927e..0c666fe 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,7 +54,7 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '1RZ2V', options ) ); } if ( hasOwnProp( options, 'thisArg' ) ) { opts.thisArg = options.thisArg; @@ -62,13 +62,13 @@ function validate( opts, options ) { if ( hasOwnProp( options, 'series' ) ) { opts.series = options.series; if ( !isBoolean( opts.series ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'series', opts.series ) ); + return new TypeError( format( '1RZ2o', 'series', opts.series ) ); } } if ( hasOwnProp( options, 'limit' ) ) { opts.limit = options.limit; if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'limit', opts.limit ) ); + return new TypeError( format( '1RZ3P', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index 5470344..88d046d 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-plain-object": "^0.2.1", "@stdlib/assert-is-positive-integer": "^0.2.1", "@stdlib/constants-float64-pinf": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", "debug": "^2.6.9" From 5429fbfe262d4deb1696cbc5b59ff6495c46ebb5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 24 Feb 2024 17:55:55 +0000 Subject: [PATCH 100/147] Remove files --- index.d.ts | 410 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6592 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index f6cba5d..0000000 --- a/index.d.ts +++ /dev/null @@ -1,410 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Execution context. - */ - thisArg?: ThisParameterType>; - - /** - * The maximum number of pending invocations at any one time. - */ - limit?: number; - - /** - * Boolean indicating whether to sequentially invoke the reducer function for each `collection` element. If `true`, the function sets `options.limit=1`. Default: true. - */ - series?: boolean; -} - -/** -* Callback function. -*/ -type Nullary = () => void; - -/** -* Callback function. -* -* @param error - encountered error or null -*/ -type Unary = ( error: Error | null ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Binary = ( error: Error | null, accumulator: U ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param next - a callback to be invoked after processing a collection `value` -*/ -type TernaryReducer = ( this: V, accumulator: U, value: T, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuaternaryReducer = ( this: V, accumulator: U, value: T, index: number, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuinaryReducer = ( this: V, accumulator: U, value: T, index: number, collection: Collection, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type Reducer = TernaryReducer | QuaternaryReducer | QuinaryReducer; - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result. -* -* @param collection - input collection -* @param initial - initial value -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( collection: Collection, initial: U, done: Callback ) => void; - -/** -* Interface for `reduceRightAsync`. -*/ -interface ReduceRightAsync { - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, {}, read, done ); - */ - ( collection: Collection, initial: U, options: Options, reducer: Reducer, done: Callback ): void; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, read, done ); - */ - ( collection: Collection, initial: U, reducer: Reducer, done: Callback ): void; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @throws must provide valid options - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var opts = { - * 'series': false - * }; - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( opts, read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( options: Options, reducer: Reducer ): FactoryFunction; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param reducer - function to invoke for each element in a collection - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( reducer: Reducer ): FactoryFunction; -} - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param collection - input collection -* @param initial - initial value -* @param options - function options -* @param options.thisArg - execution context -* @param options.limit - maximum number of pending invocations at any one time -* @param 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 (default: true) -* @param reducer - function to invoke for each element in a collection -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -declare var reduceRightAsync: ReduceRightAsync; - - -// EXPORTS // - -export = reduceRightAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index be882ad..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.0-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.0-esm/index.mjs";import{isPrimitive as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.1.0-esm/index.mjs";function a(e,t){return s(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(n("invalid option. `%s` option must be a boolean. Option: `%s`.","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!m(e.limit))?new TypeError(n("invalid option. `%s` option must be a positive integer. Option: `%s`.","limit",e.limit)):null):new TypeError(n("invalid argument. Options argument must be an object. Value: `%s`.",t))}function u(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){if(this instanceof e){var i=[null];i.push.apply(i,arguments);var n=Function.bind.apply(t,i);return new n}return t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})})),i}var d=u(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function c(e,t,i,n,r){var s,o,l,m,a,u;if(m=e.length,d("Collection length: %d",m),0===m)return d("Finished processing a collection."),r(null,t);for(l=m0&&c();function c(){function r(e,i){if(!o){if(e)return o=!0,p(e);d("Accumulator: %s",JSON.stringify(i)),t=i,p()}}d("Collection element %d: %s.",a-=1,JSON.stringify(e[a])),3===n.length?n.call(i.thisArg,t,e[a],r):4===n.length?n.call(i.thisArg,t,e[a],a,r):n.call(i.thisArg,t,e[a],a,e,r)}function p(e){return e?(d("Encountered an error: %s",e.message),r(e)):(d("Processed %d of %d collection elements.",s+=1,m),a>0?c():s===m?(d("Finished processing a collection."),r(null,t)):void 0)}}function p(e,s){var o,l,m;if(o={},arguments.length>1){if(l=a(o,e))throw l;m=s}else m=e;if(!t(m))throw new TypeError(n("invalid argument. Last argument must be a function. Value: `%s`.",m));return void 0===o.series&&void 0===o.limit&&(o.series=!0),o.series?o.limit=1:o.limit||(o.limit=r),u;function u(e,r,s){if(!i(e))throw new TypeError(n("invalid argument. First argument must be a collection. Value: `%s`.",e));if(!t(s))throw new TypeError(n("invalid argument. Last argument must be a function. Value: `%s`.",s));return c(e,r,o,m,(function(e,t){if(e)return s(e);s(null,t)}))}}function f(e,t,i,n,r){if(arguments.length<5)return p(i)(e,t,n);p(i,n)(e,t,r)}e(f,"factory",p);export{f as default,p as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 42fb408..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/limit.js","../lib/factory.js","../lib/main.js","../lib/index.js"],"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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@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\nexport default 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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/string-format';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\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 === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, 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 ( !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, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","logger","collection","acc","fcn","done","count","flg","lim","len","idx","i","length","next","cb","error","result","clbk","JSON","stringify","call","message","factory","err","f","arguments","isFunction","PINF","reduceRightAsync","initial","isCollection","setReadOnly","main"],"mappings":";;+4BAsDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,IAGXE,EAAYF,EAAS,aACzBD,EAAKI,QAAUH,EAAQG,SAEnBD,EAAYF,EAAS,YACzBD,EAAKK,OAASJ,EAAQI,QAChBC,EAAWN,EAAKK,SACd,IAAIE,UAAWC,EAAQ,+DAAgE,SAAUR,EAAKK,SAG1GF,EAAYF,EAAS,WACzBD,EAAKS,MAAQR,EAAQQ,OACfC,EAAmBV,EAAKS,QACtB,IAAIF,UAAWC,EAAQ,wEAAyE,QAASR,EAAKS,QAGhH,MAjBC,IAAIF,UAAWC,EAAQ,qEAAsEP,GAkBtG,8eC/CIU,uDAAQC,CAAQ,4BAkBpB,SAASH,EAAOI,EAAYC,EAAKd,EAAMe,EAAKC,GAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMP,EAAWU,OACjBZ,EAAO,wBAAyBS,GAEnB,IAARA,EAEJ,OADAT,EAAO,qCACAK,EAAM,KAAMF,GAYpB,IATCK,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAEZE,EAAO,wBAAyBQ,GAChCR,EAAO,0BAA2BI,EAAIQ,QAEtCN,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVG,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKT,EAAL,CAIA,GAAKQ,EAEJ,OADAR,GAAM,EACCU,EAAMF,GAEdf,EAAO,kBAAmBkB,KAAKC,UAAWH,IAC1Cb,EAAMa,EACNC,GAPC,CAQD,CA5BDjB,EAAO,6BADPU,GAAO,EACmCQ,KAAKC,UAAWjB,EAAYQ,KAClD,IAAfN,EAAIQ,OACRR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOI,GACtB,IAAfV,EAAIQ,OACfR,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKI,GAErDV,EAAIgB,KAAM/B,EAAKI,QAASU,EAAKD,EAAYQ,GAAOA,EAAKR,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJf,EAAO,2BAA4Be,EAAMM,SAClChB,EAAMU,KAGdf,EAAO,0CADPM,GAAS,EACgDG,GACpDC,EAAM,EACHG,IAEHP,IAAUG,GACdT,EAAO,qCACAK,EAAM,KAAMF,SAFpB,EAIA,CACF,CCzCA,SAASmB,EAAShC,EAASc,GAC1B,IAAIf,EACAkC,EACAC,EAGJ,GADAnC,EAAO,CAAA,EACFoC,UAAUb,OAAS,EAAI,CAE3B,GADAW,EAAMnC,EAAUC,EAAMC,GAErB,MAAMiC,EAEPC,EAAIpB,CACN,MACEoB,EAAIlC,EAEL,IAAMoC,EAAYF,GACjB,MAAM,IAAI5B,UAAWC,EAAQ,mEAAoE2B,IAUlG,YARqB,IAAhBnC,EAAKK,aAAoC,IAAfL,EAAKS,QACnCT,EAAKK,QAAS,GAEVL,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQ6B,GAEPC,EAaP,SAASA,EAAkB1B,EAAY2B,EAASxB,GAC/C,IAAMyB,EAAc5B,GACnB,MAAM,IAAIN,UAAWC,EAAQ,sEAAuEK,IAErG,IAAMwB,EAAYrB,GACjB,MAAM,IAAIT,UAAWC,EAAQ,mEAAoEQ,IAElG,OAAOP,EAAOI,EAAY2B,EAASxC,EAAMmC,GAUzC,SAAeT,EAAOZ,GACrB,GAAKY,EACJ,OAAOV,EAAMU,GAEdV,EAAM,KAAMF,EACZ,GACD,CACF,CC1EA,SAASyB,EAAkB1B,EAAY2B,EAASvC,EAASc,EAAKC,GAC7D,GAAKoB,UAAUb,OAAS,EACvB,OAAOU,EAAShC,EAATgC,CAAoBpB,EAAY2B,EAASzB,GAEjDkB,EAAShC,EAASc,EAAlBkB,CAAyBpB,EAAY2B,EAASxB,EAC/C,CClBA0B,EAAAC,EAAA,UAAAV"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 4728e9e..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From e30aa21b4b078c94e3acc1ca7b2854ad5e71e904 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 24 Feb 2024 17:56:13 +0000 Subject: [PATCH 101/147] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 ---- .github/workflows/publish.yml | 249 -- .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 132 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.factory.js | 73 - benchmark/benchmark.js | 160 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 224 - docs/types/test.ts | 166 - examples/index.js | 55 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 164 - lib/index.js | 77 - lib/limit.js | 142 - lib/main.js | 95 - lib/validate.js | 80 - package.json | 64 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 1095 ----- test/test.js | 38 - test/test.main.js | 1035 ----- test/test.validate.js | 181 - 49 files changed, 4873 insertions(+), 6950 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/limit.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1e08946..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 5358060..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index fa37f2d..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '37 1 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9106b5d..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -460,7 +457,7 @@ reduceRightAsync( files, acc, read, done ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -531,11 +528,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right +[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right/tree/esm -[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce +[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index b155fd2..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var reduceRightAsync; - var arr; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - reduceRightAsync = factory( onItem ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - var acc; - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index af5c346..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var reduceRightAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=false', function benchmark( b ) { - var opts; - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'series': false - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var arr; - var len; - var acc; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'limit': 3 - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b8adcd2..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right" -%% click B href "https://github.com/stdlib-js/utils-async-reduce-right/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-reduce-right/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-reduce-right/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-reduce-right/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right -[production-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-async-reduce-right/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-async-reduce-right/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-async-reduce-right/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 47a072e..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import reduceRightAsync from '../docs/types/index'; -export = reduceRightAsync; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 530ca4d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var c=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var x=c(function(U,O){ -var R=require('@stdlib/assert-is-plain-object/dist'),h=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,k=require('@stdlib/assert-is-positive-integer/dist').isPrimitive,d=require('@stdlib/error-tools-fmtprodmsg/dist');function I(e,r){return R(r)?(h(r,"thisArg")&&(e.thisArg=r.thisArg),h(r,"series")&&(e.series=r.series,!j(e.series))?new TypeError(d('1RZ2o',"series",e.series)):h(r,"limit")&&(e.limit=r.limit,!k(e.limit))?new TypeError(d('1RZ3P',"limit",e.limit)):null):new TypeError(d('1RZ2V',r));}O.exports=I -});var P=c(function(W,E){ -var J=require("debug"),a=J("reduce-right-async:limit");function L(e,r,i,t,s){var f,m,v,n,u,g;if(n=e.length,a("Collection length: %d",n),n===0)return a("Finished processing a collection."),s(null,r);for(n0&&o();function o(){u-=1,a("Collection element %d: %s.",u,JSON.stringify(e[u])),t.length===3?t.call(i.thisArg,r,e[u],l):t.length===4?t.call(i.thisArg,r,e[u],u,l):t.call(i.thisArg,r,e[u],u,e,l);function l(w,A){if(!m){if(w)return m=!0,b(w);a("Accumulator: %s",JSON.stringify(A)),r=A,b()}}}function b(l){if(l)return a("Encountered an error: %s",l.message),s(l);if(f+=1,a("Processed %d of %d collection elements.",f,n),u>0)return o();if(f===n)return a("Finished processing a collection."),s(null,r)}}E.exports=L -});var q=c(function(X,F){ -var T=require('@stdlib/assert-is-function/dist'),S=require('@stdlib/assert-is-collection/dist'),y=require('@stdlib/error-tools-fmtprodmsg/dist'),B=require('@stdlib/constants-float64-pinf/dist'),z=x(),D=P();function G(e,r){var i,t,s;if(i={},arguments.length>1){if(t=z(i,e),t)throw t;s=r}else s=e;if(!T(s))throw new TypeError(y('1RZ3q',s));return i.series===void 0&&i.limit===void 0&&(i.series=!0),i.series?i.limit=1:i.limit||(i.limit=B),f;function f(m,v,n){if(!S(m))throw new TypeError(y('1RZAh',m));if(!T(n))throw new TypeError(y('1RZ3q',n));return D(m,v,i,s,u);function u(g,o){if(g)return n(g);n(null,o)}}}F.exports=G -});var N=c(function(Y,C){ -var p=q();function H(e,r,i,t,s){if(arguments.length<5)return p(i)(e,r,t);p(i,t)(e,r,s)}C.exports=H -});var K=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),V=N(),M=q();K(V,"factory",M);module.exports=V; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index acb9d67..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/limit.js", "../lib/factory.js", "../lib/main.js", "../lib/index.js"], - "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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\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 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 to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\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 === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, 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 ( !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, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\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* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nmodule.exports = reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' );\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, 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"], - "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,0BAA2B,EAkB/C,SAASE,EAAOC,EAAYC,EAAKC,EAAMC,EAAKC,EAAO,CAClD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMR,EAAW,OACjBF,EAAO,wBAAyBU,CAAI,EAE/BA,IAAQ,EACZ,OAAAV,EAAO,mCAAoC,EACpCM,EAAM,KAAMH,CAAI,EAYxB,IAVKO,EAAMN,EAAK,MACfK,EAAMC,EAEND,EAAML,EAAK,MAEZJ,EAAO,wBAAyBS,CAAI,EACpCT,EAAO,0BAA2BK,EAAI,MAAO,EAE7CE,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVE,EAAK,EAQP,SAASA,GAAO,CACfF,GAAO,EACPX,EAAO,6BAA8BW,EAAK,KAAK,UAAWT,EAAYS,CAAI,CAAE,CAAE,EACzEN,EAAI,SAAW,EACnBA,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGG,CAAG,EACxCT,EAAI,SAAW,EAC1BA,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGA,EAAKG,CAAG,EAExDT,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGA,EAAKT,EAAYY,CAAG,EAUrE,SAASA,EAAIC,EAAOC,EAAS,CAC5B,GAAK,CAAAR,EAIL,IAAKO,EACJ,OAAAP,EAAM,GACCS,EAAMF,CAAM,EAEpBf,EAAO,kBAAmB,KAAK,UAAWgB,CAAO,CAAE,EACnDb,EAAMa,EACNC,EAAK,EACN,CACD,CASA,SAASA,EAAMF,EAAQ,CACtB,GAAKA,EACJ,OAAAf,EAAO,2BAA4Be,EAAM,OAAQ,EAC1CT,EAAMS,CAAM,EAIpB,GAFAR,GAAS,EACTP,EAAO,0CAA2CO,EAAOG,CAAI,EACxDC,EAAM,EACV,OAAOE,EAAK,EAEb,GAAKN,IAAUG,EACd,OAAAV,EAAO,mCAAoC,EACpCM,EAAM,KAAMH,CAAI,CAEzB,CACD,CAKAL,EAAO,QAAUG,IC7IjB,IAAAiB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,gCAAiC,EACjDC,EAAW,IACXC,EAAQ,IAoEZ,SAASC,EAASC,EAASC,EAAM,CAChC,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,CAACP,EAAYW,CAAE,EACnB,MAAM,IAAI,UAAWT,EAAQ,mEAAoES,CAAE,CAAE,EAEtG,OAAKF,EAAK,SAAW,QAAUA,EAAK,QAAU,SAC7CA,EAAK,OAAS,IAEVA,EAAK,OACTA,EAAK,MAAQ,EACDA,EAAK,QACjBA,EAAK,MAAQN,GAEPS,EAaP,SAASA,EAAkBC,EAAYC,EAASC,EAAO,CACtD,GAAK,CAACd,EAAcY,CAAW,EAC9B,MAAM,IAAI,UAAWX,EAAQ,sEAAuEW,CAAW,CAAE,EAElH,GAAK,CAACb,EAAYe,CAAK,EACtB,MAAM,IAAI,UAAWb,EAAQ,mEAAoEa,CAAK,CAAE,EAEzG,OAAOV,EAAOQ,EAAYC,EAASL,EAAME,EAAGK,CAAK,EAUjD,SAASA,EAAMC,EAAOC,EAAM,CAC3B,GAAKD,EACJ,OAAOF,EAAME,CAAM,EAEpBF,EAAM,KAAMG,CAAI,CACjB,CACD,CACD,CAKAnB,EAAO,QAAUO,ICnKjB,IAAAa,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,IA8Dd,SAASC,EAAkBC,EAAYC,EAASC,EAASC,EAAKC,EAAO,CACpE,GAAK,UAAU,OAAS,EACvB,OAAON,EAASI,CAAQ,EAAGF,EAAYC,EAASE,CAAI,EAErDL,EAASI,EAASC,CAAI,EAAGH,EAAYC,EAASG,CAAK,CACpD,CAKAP,EAAO,QAAUE,IC9BjB,IAAIM,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "isPositiveInteger", "format", "validate", "opts", "options", "require_limit", "__commonJSMin", "exports", "module", "logger", "debug", "limit", "collection", "acc", "opts", "fcn", "done", "count", "flg", "lim", "len", "idx", "i", "next", "cb", "error", "result", "clbk", "require_factory", "__commonJSMin", "exports", "module", "isFunction", "isCollection", "format", "PINF", "validate", "limit", "factory", "options", "fcn", "opts", "err", "f", "reduceRightAsync", "collection", "initial", "done", "clbk", "error", "acc", "require_main", "__commonJSMin", "exports", "module", "factory", "reduceRightAsync", "collection", "initial", "options", "fcn", "done", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3f22669..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,224 +0,0 @@ - -{{alias}}( collection, initial, [options,] reducer, done ) - Applies a function against an accumulator and each element in a collection - and returns the accumulated result, iterating from right to left. - - When invoked, `reducer` is provided a maximum of five arguments: - - - `accumulator`: accumulated value - - `value`: collection value - - `index`: collection index - - `collection`: the input collection - - `next`: a callback to be invoked after processing a collection `value` - - The actual number of provided arguments depends on function length. If - `reducer` accepts three arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `next` - - If `reducer` accepts four arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `index` - - `next` - - For every other `reducer` signature, `reducer` is provided all five - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `accumulator`: accumulated value - - If a provided function calls the `next` callback with a truthy `error` - argument, the function suspends execution and immediately calls the `done` - callback for subsequent `error` handling. - - Execution is *not* guaranteed to be asynchronous. To guarantee asynchrony, - 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`). - - The function does not support dynamic collection resizing. - - If provided an empty collection, the function invokes the `done` callback - with the `initial` value as the second argument. - - The function does not skip `undefined` elements. - - When processing collection elements concurrently, *beware* of race - conditions when updating an accumulator. This is especially true when an - accumulator is a primitive (e.g., a number). In general, prefer object - accumulators. - - Parameters - ---------- - collection: Array|TypedArray|Object - Input collection over which to iterate. If provided an object, the - object must be array-like (excluding strings and functions). - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - reducer: Function - The function to invoke for each element in a collection. - - done: Function - A callback invoked either upon processing all collection elements or - upon encountering an error. - - Examples - -------- - // Basic usage: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, fcn, done ) - 3000 - 2500 - 1000 - 6500 - - // Limit number of concurrent invocations: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'limit': 2 }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 2500 - 3000 - 1000 - 6500 - - // Process concurrently: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'series': false }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 1000 - 2500 - 3000 - 6500 - - -{{alias}}.factory( [options,] fcn ) - Returns a function which applies a function against an accumulator and each - element in a collection and returns the accumulated result, iterating from - right to left. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - fcn: Function - The function to invoke for each element in a collection. - - Returns - ------- - out: Function - A function which invokes a function for each element in a collection. - - Examples - -------- - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > var opts = { 'series': false }; - > var f = {{alias}}.factory( opts, fcn ); - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > f( arr, acc, done ) - 1000 - 2500 - 3000 - 6500 - > acc = { 'sum': 0 }; - > arr = [ 1000, 1500, 2000 ]; - > f( arr, acc, done ) - 1000 - 1500 - 2000 - 4500 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0455864..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,166 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unsafe-assignment */ - -import reduceRightAsync = require( './index' ); - -const reducer = ( acc: any, value: number, index: number, next: Function ) => { - acc.sum += value; - if ( index === void 0 ) { - throw new Error( '`index` is missing.' ); - } - next( null, acc ); -}; - -const done = ( error: Error | null, acc: any ) => { - if ( error ) { - throw error; - } - if ( acc === void 0 ) { - throw new Error( '`acc` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( 2, acc, reducer, done ); // $ExpectError - reduceRightAsync( false, acc, reducer, done ); // $ExpectError - reduceRightAsync( true, acc, reducer, done ); // $ExpectError - reduceRightAsync( {}, acc, reducer, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a predicate argument which is not a predicate function... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 2, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, false, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, true, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 'abc', done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, [], done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a done callback argument which is not a function having a supported signature... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 2 ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, false ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, true ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 'abc' ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, {} ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, [] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const acc = { 'sum': 0 }; - reduceRightAsync(); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, reducer, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - reduceRightAsync.factory( reducer ); // $ExpectType FactoryFunction - reduceRightAsync.factory( { 'series': true }, reducer ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - reduceRightAsync.factory( [], reducer ); // $ExpectError - reduceRightAsync.factory( 123, reducer ); // $ExpectError - reduceRightAsync.factory( 'abc', reducer ); // $ExpectError - reduceRightAsync.factory( false, reducer ); // $ExpectError - reduceRightAsync.factory( true, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not a predicate function... -{ - reduceRightAsync.factory( {} ); // $ExpectError - reduceRightAsync.factory( true ); // $ExpectError - reduceRightAsync.factory( false ); // $ExpectError - reduceRightAsync.factory( {}, 123 ); // $ExpectError - reduceRightAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1( 12, acc, done ); // $ExpectError - fcn1( true, acc, done ); // $ExpectError - fcn1( false, acc, done ); // $ExpectError - fcn1( {}, acc, done ); // $ExpectError - - fcn1( [ 3000, 2500, 1000 ], acc, 12 ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, true ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, false ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, '5' ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, {} ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, [] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1(); // $ExpectError - fcn1( [ 3000, 2500, 1000 ] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - reduceRightAsync.factory( { 'limit': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': true }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': false }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - reduceRightAsync.factory( { 'series': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': 12 }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - reduceRightAsync.factory(); // $ExpectError - reduceRightAsync.factory( {}, reducer, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index dd64345..0000000 --- a/examples/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var resolve = require( 'path' ).resolve; -var readFile = require( '@stdlib/fs-read-file' ); -var reduceRightAsync = require( './../lib' ); - -var files = [ - resolve( __dirname, '..', 'package.json' ), - resolve( __dirname, '..', 'README.md' ) -]; - -function done( error, acc ) { - if ( error ) { - throw error; - } - console.log( acc.count ); -} - -function read( acc, file, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( file, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( null, acc ); - } - acc.count += 1; - next( null, acc ); - } -} - -var acc = { - 'count': 0 -}; -reduceRightAsync( files, acc, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 28e0a36..f6cba5d 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..51a7543 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import{isPrimitive as c}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.1-esm/index.mjs";function m(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var d=m(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function f(e,m){var f,u,p;if(f={},arguments.length>1){if(u=function(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("1RZ2o","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!c(e.limit))?new TypeError(r("1RZ3P","limit",e.limit)):null):new TypeError(r("1RZ2V",t))}(f,e),u)throw u;p=m}else p=e;if(!t(p))throw new TypeError(r("1RZ3q",p));return void 0===f.series&&void 0===f.limit&&(f.series=!0),f.series?f.limit=1:f.limit||(f.limit=s),function(e,s,n){if(!i(e))throw new TypeError(r("1RZAh",e));if(!t(n))throw new TypeError(r("1RZ3q",n));return function(e,t,i,r,s){var n,o,l,c,m,f;if(c=e.length,d("Collection length: %d",c),0===c)return d("Finished processing a collection."),s(null,t);for(l=c0&&u();function u(){function s(e,i){if(!o){if(e)return o=!0,p(e);d("Accumulator: %s",JSON.stringify(i)),t=i,p()}}d("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function p(e){return e?(d("Encountered an error: %s",e.message),s(e)):(d("Processed %d of %d collection elements.",n+=1,c),m>0?u():n===c?(d("Finished processing a collection."),s(null,t)):void 0)}}(e,s,f,p,(function(e,t){if(e)return n(e);n(null,t)}))}}function u(e,t,i,r,s){if(arguments.length<5)return f(i)(e,t,r);f(i,r)(e,t,s)}e(u,"factory",f);export{u as default,f as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..e11f2cb --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/limit.js","../lib/factory.js","../lib/validate.js","../lib/main.js","../lib/index.js"],"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 logger = require( 'debug' );\n\n\n// VARIABLES //\n\nvar debug = logger( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RZ3q', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '1RZAh', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RZ3q', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '1RZ2V', 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( '1RZ2o', '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( '1RZ3P', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["debug","logger","factory","options","fcn","opts","err","f","arguments","length","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","validate","isFunction","PINF","collection","initial","done","isCollection","acc","count","flg","lim","len","idx","i","next","cb","error","result","clbk","JSON","stringify","call","message","reduceRightAsync","setReadOnly","main"],"mappings":";;81CA2BIA,uDAAQC,CAAQ,4BCoEpB,SAASC,EAASC,EAASC,GAC1B,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAA,EACFG,UAAUC,OAAS,EAAI,CAE3B,GADAH,EChDF,SAAmBD,EAAMF,GACxB,OAAMO,EAAUP,IAGXQ,EAAYR,EAAS,aACzBE,EAAKO,QAAUT,EAAQS,SAEnBD,EAAYR,EAAS,YACzBE,EAAKQ,OAASV,EAAQU,QAChBC,EAAWT,EAAKQ,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUX,EAAKQ,SAGnDF,EAAYR,EAAS,WACzBE,EAAKY,MAAQd,EAAQc,OACfC,EAAmBb,EAAKY,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASX,EAAKY,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASb,GAkBzC,CD4BQgB,CAAUd,EAAMF,GACjBG,EACJ,MAAMA,EAEPC,EAAIH,CACN,MACEG,EAAIJ,EAEL,IAAMiB,EAAYb,GACjB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAUvC,YARqB,IAAhBF,EAAKQ,aAAoC,IAAfR,EAAKY,QACnCZ,EAAKQ,QAAS,GAEVR,EAAKQ,OACTR,EAAKY,MAAQ,EACDZ,EAAKY,QACjBZ,EAAKY,MAAQI,GAed,SAA2BC,EAAYC,EAASC,GAC/C,IAAMC,EAAcH,GACnB,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,IAAMF,EAAYI,GACjB,MAAM,IAAIT,UAAWC,EAAQ,QAASQ,IAEvC,ODhGF,SAAgBF,EAAYI,EAAKrB,EAAMD,EAAKoB,GAC3C,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMR,EAAWb,OACjBT,EAAO,wBAAyB8B,GAEnB,IAARA,EAEJ,OADA9B,EAAO,qCACAwB,EAAM,KAAME,GAYpB,IATCG,EADIC,EAAMzB,EAAKY,MACTa,EAEAzB,EAAKY,MAEZjB,EAAO,wBAAyB6B,GAChC7B,EAAO,0BAA2BI,EAAIK,QAEtCkB,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVE,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKR,EAAL,CAIA,GAAKO,EAEJ,OADAP,GAAM,EACCS,EAAMF,GAEdnC,EAAO,kBAAmBsC,KAAKC,UAAWH,IAC1CV,EAAMU,EACNC,GAPC,CAQD,CA5BDrC,EAAO,6BADP+B,GAAO,EACmCO,KAAKC,UAAWjB,EAAYS,KAClD,IAAf3B,EAAIK,OACRL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOG,GACtB,IAAf9B,EAAIK,OACfL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKG,GAErD9B,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKT,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJnC,EAAO,2BAA4BmC,EAAMM,SAClCjB,EAAMW,KAGdnC,EAAO,0CADP2B,GAAS,EACgDG,GACpDC,EAAM,EACHE,IAEHN,IAAUG,GACd9B,EAAO,qCACAwB,EAAM,KAAME,SAFpB,EAIA,CACF,CCKST,CAAOK,EAAYC,EAASlB,EAAME,GAUzC,SAAe4B,EAAOT,GACrB,GAAKS,EACJ,OAAOX,EAAMW,GAEdX,EAAM,KAAME,EACZ,GACD,CACF,CE1EA,SAASgB,EAAkBpB,EAAYC,EAASpB,EAASC,EAAKoB,GAC7D,GAAKhB,UAAUC,OAAS,EACvB,OAAOP,EAASC,EAATD,CAAoBoB,EAAYC,EAASnB,GAEjDF,EAASC,EAASC,EAAlBF,CAAyBoB,EAAYC,EAASC,EAC/C,CClBAmB,EAAAC,EAAA,UAAA1C"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index e107128..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,164 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var validate = require( './validate.js' ); -var limit = require( './limit.js' ); - - -// MAIN // - -/** -* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} last argument must be a function -* @returns {Function} function which invokes the provided function once for each element in a collection -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error, data ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var opts = { -* 'series': false -* }; -* -* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: -* var reduceRightAsync = factory( opts, read ); -* -* // Create a collection over which to iterate: -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* // Define a callback which handles errors: -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* // Run `read` for each element in `files`: -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, done ); -*/ -function factory( options, fcn ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = fcn; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '1RZ3q', f ) ); - } - if ( opts.series === void 0 && opts.limit === void 0 ) { - opts.series = true; - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return reduceRightAsync; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * @private - * @param {Collection} collection - input collection - * @param {*} initial - initial value - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be a collection - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function reduceRightAsync( collection, initial, done ) { - if ( !isCollection( collection ) ) { - throw new TypeError( format( '1RZAh', collection ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '1RZ3q', done ) ); - } - return limit( collection, initial, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {*} [acc] - accumulated value - * @returns {void} - */ - function clbk( error, acc ) { - if ( error ) { - return done( error ); - } - done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ae657ff..0000000 --- a/lib/index.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* @module @stdlib/utils-async-reduce-right -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' ); -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/limit.js b/lib/limit.js deleted file mode 100644 index cdb60af..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); - - -// VARIABLES // - -var debug = logger( 'reduce-right-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each element in a collection, limiting the number of concurrently pending functions and iterating from right to left. -* -* @private -* @param {Collection} collection - input collection -* @param {*} acc - initial value -* @param {Options} opts - function options -* @param {*} [opts.thisArg] - execution context -* @param {PositiveInteger} [opts.limit] - maximum number of pending function invocations -* @param {Function} fcn - function to invoke -* @param {Callback} done - function to invoke upon completion or upon encountering an error -* @returns {void} -*/ -function limit( collection, acc, opts, fcn, done ) { - var count; - var flg; - var lim; - var len; - var idx; - var i; - - len = collection.length; - debug( 'Collection length: %d', len ); - - if ( len === 0 ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - count = 0; - idx = len; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all collection elements... - if ( idx > 0 ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next element in a collection. - * - * @private - */ - function next() { - idx -= 1; - debug( 'Collection element %d: %s.', idx, JSON.stringify( collection[ idx ] ) ); - if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], cb ); - } else if ( fcn.length === 4 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, cb ); - } else { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len - } - /** - * Callback invoked once a provided function finishes processing a collection element. - * - * @private - * @param {*} [error] - error - * @param {*} [result] - accumulation result - * @returns {void} - */ - function cb( error, result ) { - if ( flg ) { - // Prevent further processing of collection elements: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Accumulator: %s', JSON.stringify( result ) ); - acc = result; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next collection element. - * - * @private - * @param {*} [error] - error - * @returns {void} - */ - function clbk( error ) { - if ( error ) { - debug( 'Encountered an error: %s', error.message ); - return done( error ); - } - count += 1; - debug( 'Processed %d of %d collection elements.', count, len ); - if ( idx > 0 ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index c8b0d0f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param {Collection} collection - input collection -* @param {*} initial - initial value -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} second-to-last argument must be a function -* @throws {TypeError} last argument must be a function -* @returns {void} -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -function reduceRightAsync( collection, initial, options, fcn, done ) { - if ( arguments.length < 5 ) { - return factory( options )( collection, initial, fcn ); - } - factory( options, fcn )( collection, initial, done ); -} - - -// EXPORTS // - -module.exports = reduceRightAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 0c666fe..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @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 -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'thisArg': {}, -* 'series': false, -* 'limit': 10 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '1RZ2V', options ) ); - } - if ( hasOwnProp( options, 'thisArg' ) ) { - opts.thisArg = options.thisArg; - } - if ( hasOwnProp( options, 'series' ) ) { - opts.series = options.series; - if ( !isBoolean( opts.series ) ) { - return new TypeError( format( '1RZ2o', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '1RZ3P', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 88d046d..3464c63 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,43 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-boolean": "^0.2.1", - "@stdlib/assert-is-collection": "^0.2.1", - "@stdlib/assert-is-function": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/assert-is-positive-integer": "^0.2.1", - "@stdlib/constants-float64-pinf": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/constants-float64-eps": "^0.2.1", - "@stdlib/fs-read-file": "^0.2.1", - "@stdlib/utils-noop": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.0" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..b18992d --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 8244931..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1095 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( {}, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, next ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - factory( opts, next ); - }; - } -}); - -tape( 'the function returns a function (no options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided a collection (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a collection (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (1 argument)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (2 arguments)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with five arguments', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn() { - var value; - var next; - var acc; - var k; - - acc = arguments[ 0 ]; - value = arguments[ 1 ]; - k = arguments[ 2 ]; - next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( k, i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the returned function supports processing collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements concurrently', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 100, 250, 300 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements sequentially (limit = 1)', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of collection elements which are processed at any one time', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 250, 300, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 250, 100, 300 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var reduceRightAsync; - var arr; - - reduceRightAsync = factory( fcn ); - arr = []; - - reduceRightAsync( arr, 0, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var reduceRightAsync; - var obj; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = []; - obj = {}; - reduceRightAsync( arr, obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - i = 0; - - reduceRightAsync( arr, {}, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, acc ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the returned function does not skip empty elements', function test( t ) { - var reduceRightAsync; - var expected; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index f273a40..0000000 --- a/test/test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof reduceRightAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 1893240..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1035 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a collection', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (no options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, next, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, 0 ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - reduceRightAsync( [ 1, 2, 3 ], 0, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (1 argument)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (2 arguments)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with five arguments', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn() { - var next; - var acc; - var v; - - next = arguments[ 4 ]; - acc = arguments[ 0 ]; - v = arguments[ 1 ]; - - i -= 1; - j += 1; - - t.strictEqual( v, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, v ); - - function onTimeout() { - acc.sum += v; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'by default, the function processes collection elements sequentially', function test( t ) { - var values; - var count; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements concurrently', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 100, 250, 300 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': true - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially (limit = 1)', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var arr; - var ctx; - - arr = [ 3, 2, 1 ]; - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 3, 2, 1 ]; - opts = { - 'series': true - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 250, 100, 300 ]; - opts = { - 'limit': 2 - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var arr = []; - reduceRightAsync( arr, 0, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var arr = []; - var obj = {}; - - reduceRightAsync( arr, obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - arr = [ 3, 2, 1 ]; - i = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, value ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the function does not skip empty elements', function test( t ) { - var expected; - var arr; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, fcn, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 7660838..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,181 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `limit` option which is not a positive integer', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - -5, - 0, - 3.14, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'limit': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `series` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'series': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function accepts any value for the `thisArg` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'thisArg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err, null, 'returns null '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'thisArg': {}, - 'series': false, - 'limit': 10 - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From 0c3af7f89870036bea3190b77688fc5ceeb7b83e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 24 Feb 2024 18:48:18 +0000 Subject: [PATCH 102/147] Update README.md for ESM bundle v0.2.1 --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1115877..712e79b 100644 --- a/README.md +++ b/README.md @@ -52,13 +52,13 @@ limitations under the License. ## Usage ```javascript -import reduceRightAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-reduce-right@esm/index.mjs'; +import reduceRightAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-reduce-right@v0.2.1-esm/index.mjs'; ``` You can also import the following named exports from the package: ```javascript -import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-reduce-right@esm/index.mjs'; +import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-reduce-right@v0.2.1-esm/index.mjs'; ``` #### reduceRightAsync( collection, initial, \[options,] reducer, done ) @@ -381,7 +381,7 @@ The function accepts the same `options` as `reduceRightAsync()`. var resolve = require( 'path' ).resolve; import readFile from 'https://cdn.jsdelivr.net/gh/stdlib-js/fs-read-file@esm/index.mjs'; -import reduceRightAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-reduce-right@esm/index.mjs'; +import reduceRightAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-reduce-right@v0.2.1-esm/index.mjs'; var files = [ resolve( __dirname, 'package.json' ), From a88a3acf37543c37013ee3b78a015b1321884a95 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 24 Feb 2024 18:48:18 +0000 Subject: [PATCH 103/147] Auto-generated commit --- README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 712e79b..1b24212 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import reduceRightAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-reduce-right@esm/index.mjs'; +``` +The previous example will load the latest bundled code from the esm branch. Alternatively, you may load a specific version by loading the file from one of the [tagged bundles](https://github.com/stdlib-js/utils-async-reduce-right/tags). For example, + ```javascript import reduceRightAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-reduce-right@v0.2.1-esm/index.mjs'; ``` @@ -58,7 +63,7 @@ import reduceRightAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async- You can also import the following named exports from the package: ```javascript -import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-reduce-right@v0.2.1-esm/index.mjs'; +import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-reduce-right@esm/index.mjs'; ``` #### reduceRightAsync( collection, initial, \[options,] reducer, done ) @@ -381,7 +386,7 @@ The function accepts the same `options` as `reduceRightAsync()`. var resolve = require( 'path' ).resolve; import readFile from 'https://cdn.jsdelivr.net/gh/stdlib-js/fs-read-file@esm/index.mjs'; -import reduceRightAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-reduce-right@v0.2.1-esm/index.mjs'; +import reduceRightAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-reduce-right@esm/index.mjs'; var files = [ resolve( __dirname, 'package.json' ), From db84c023697389b9a44a009117fd333a902d343e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 04:21:17 +0000 Subject: [PATCH 104/147] Transform error messages --- lib/factory.js | 8 ++++---- lib/validate.js | 8 ++++---- package.json | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 1125052..e107128 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -22,7 +22,7 @@ var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var PINF = require( '@stdlib/constants-float64-pinf' ); var validate = require( './validate.js' ); var limit = require( './limit.js' ); @@ -109,7 +109,7 @@ function factory( options, fcn ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '1RZ3q', f ) ); } if ( opts.series === void 0 && opts.limit === void 0 ) { opts.series = true; @@ -134,10 +134,10 @@ function factory( options, fcn ) { */ function reduceRightAsync( collection, initial, done ) { if ( !isCollection( collection ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a collection. Value: `%s`.', collection ) ); + throw new TypeError( format( '1RZAh', collection ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '1RZ3q', done ) ); } return limit( collection, initial, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index 9ba927e..0c666fe 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,7 +54,7 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '1RZ2V', options ) ); } if ( hasOwnProp( options, 'thisArg' ) ) { opts.thisArg = options.thisArg; @@ -62,13 +62,13 @@ function validate( opts, options ) { if ( hasOwnProp( options, 'series' ) ) { opts.series = options.series; if ( !isBoolean( opts.series ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'series', opts.series ) ); + return new TypeError( format( '1RZ2o', 'series', opts.series ) ); } } if ( hasOwnProp( options, 'limit' ) ) { opts.limit = options.limit; if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'limit', opts.limit ) ); + return new TypeError( format( '1RZ3P', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index 31e9a96..eaf0e2f 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-plain-object": "^0.2.1", "@stdlib/assert-is-positive-integer": "^0.2.1", "@stdlib/constants-float64-pinf": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", "debug": "^2.6.9", From 11f2462584f83d996afb0c9be31956394a968c08 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 08:25:59 +0000 Subject: [PATCH 105/147] Remove files --- index.d.ts | 410 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5257 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index f6cba5d..0000000 --- a/index.d.ts +++ /dev/null @@ -1,410 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Execution context. - */ - thisArg?: ThisParameterType>; - - /** - * The maximum number of pending invocations at any one time. - */ - limit?: number; - - /** - * Boolean indicating whether to sequentially invoke the reducer function for each `collection` element. If `true`, the function sets `options.limit=1`. Default: true. - */ - series?: boolean; -} - -/** -* Callback function. -*/ -type Nullary = () => void; - -/** -* Callback function. -* -* @param error - encountered error or null -*/ -type Unary = ( error: Error | null ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Binary = ( error: Error | null, accumulator: U ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param next - a callback to be invoked after processing a collection `value` -*/ -type TernaryReducer = ( this: V, accumulator: U, value: T, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuaternaryReducer = ( this: V, accumulator: U, value: T, index: number, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuinaryReducer = ( this: V, accumulator: U, value: T, index: number, collection: Collection, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type Reducer = TernaryReducer | QuaternaryReducer | QuinaryReducer; - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result. -* -* @param collection - input collection -* @param initial - initial value -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( collection: Collection, initial: U, done: Callback ) => void; - -/** -* Interface for `reduceRightAsync`. -*/ -interface ReduceRightAsync { - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, {}, read, done ); - */ - ( collection: Collection, initial: U, options: Options, reducer: Reducer, done: Callback ): void; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, read, done ); - */ - ( collection: Collection, initial: U, reducer: Reducer, done: Callback ): void; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @throws must provide valid options - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var opts = { - * 'series': false - * }; - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( opts, read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( options: Options, reducer: Reducer ): FactoryFunction; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param reducer - function to invoke for each element in a collection - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( reducer: Reducer ): FactoryFunction; -} - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param collection - input collection -* @param initial - initial value -* @param options - function options -* @param options.thisArg - execution context -* @param options.limit - maximum number of pending invocations at any one time -* @param 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 (default: true) -* @param reducer - function to invoke for each element in a collection -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -declare var reduceRightAsync: ReduceRightAsync; - - -// EXPORTS // - -export = reduceRightAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 51a7543..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import{isPrimitive as c}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.1-esm/index.mjs";function m(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var d=m(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function f(e,m){var f,u,p;if(f={},arguments.length>1){if(u=function(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("1RZ2o","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!c(e.limit))?new TypeError(r("1RZ3P","limit",e.limit)):null):new TypeError(r("1RZ2V",t))}(f,e),u)throw u;p=m}else p=e;if(!t(p))throw new TypeError(r("1RZ3q",p));return void 0===f.series&&void 0===f.limit&&(f.series=!0),f.series?f.limit=1:f.limit||(f.limit=s),function(e,s,n){if(!i(e))throw new TypeError(r("1RZAh",e));if(!t(n))throw new TypeError(r("1RZ3q",n));return function(e,t,i,r,s){var n,o,l,c,m,f;if(c=e.length,d("Collection length: %d",c),0===c)return d("Finished processing a collection."),s(null,t);for(l=c0&&u();function u(){function s(e,i){if(!o){if(e)return o=!0,p(e);d("Accumulator: %s",JSON.stringify(i)),t=i,p()}}d("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function p(e){return e?(d("Encountered an error: %s",e.message),s(e)):(d("Processed %d of %d collection elements.",n+=1,c),m>0?u():n===c?(d("Finished processing a collection."),s(null,t)):void 0)}}(e,s,f,p,(function(e,t){if(e)return n(e);n(null,t)}))}}function u(e,t,i,r,s){if(arguments.length<5)return f(i)(e,t,r);f(i,r)(e,t,s)}e(u,"factory",f);export{u as default,f as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index e11f2cb..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/limit.js","../lib/factory.js","../lib/validate.js","../lib/main.js","../lib/index.js"],"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 logger = require( 'debug' );\n\n\n// VARIABLES //\n\nvar debug = logger( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RZ3q', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '1RZAh', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RZ3q', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '1RZ2V', 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( '1RZ2o', '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( '1RZ3P', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["debug","logger","factory","options","fcn","opts","err","f","arguments","length","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","validate","isFunction","PINF","collection","initial","done","isCollection","acc","count","flg","lim","len","idx","i","next","cb","error","result","clbk","JSON","stringify","call","message","reduceRightAsync","setReadOnly","main"],"mappings":";;81CA2BIA,uDAAQC,CAAQ,4BCoEpB,SAASC,EAASC,EAASC,GAC1B,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAA,EACFG,UAAUC,OAAS,EAAI,CAE3B,GADAH,EChDF,SAAmBD,EAAMF,GACxB,OAAMO,EAAUP,IAGXQ,EAAYR,EAAS,aACzBE,EAAKO,QAAUT,EAAQS,SAEnBD,EAAYR,EAAS,YACzBE,EAAKQ,OAASV,EAAQU,QAChBC,EAAWT,EAAKQ,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUX,EAAKQ,SAGnDF,EAAYR,EAAS,WACzBE,EAAKY,MAAQd,EAAQc,OACfC,EAAmBb,EAAKY,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASX,EAAKY,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASb,GAkBzC,CD4BQgB,CAAUd,EAAMF,GACjBG,EACJ,MAAMA,EAEPC,EAAIH,CACN,MACEG,EAAIJ,EAEL,IAAMiB,EAAYb,GACjB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAUvC,YARqB,IAAhBF,EAAKQ,aAAoC,IAAfR,EAAKY,QACnCZ,EAAKQ,QAAS,GAEVR,EAAKQ,OACTR,EAAKY,MAAQ,EACDZ,EAAKY,QACjBZ,EAAKY,MAAQI,GAed,SAA2BC,EAAYC,EAASC,GAC/C,IAAMC,EAAcH,GACnB,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,IAAMF,EAAYI,GACjB,MAAM,IAAIT,UAAWC,EAAQ,QAASQ,IAEvC,ODhGF,SAAgBF,EAAYI,EAAKrB,EAAMD,EAAKoB,GAC3C,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMR,EAAWb,OACjBT,EAAO,wBAAyB8B,GAEnB,IAARA,EAEJ,OADA9B,EAAO,qCACAwB,EAAM,KAAME,GAYpB,IATCG,EADIC,EAAMzB,EAAKY,MACTa,EAEAzB,EAAKY,MAEZjB,EAAO,wBAAyB6B,GAChC7B,EAAO,0BAA2BI,EAAIK,QAEtCkB,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVE,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKR,EAAL,CAIA,GAAKO,EAEJ,OADAP,GAAM,EACCS,EAAMF,GAEdnC,EAAO,kBAAmBsC,KAAKC,UAAWH,IAC1CV,EAAMU,EACNC,GAPC,CAQD,CA5BDrC,EAAO,6BADP+B,GAAO,EACmCO,KAAKC,UAAWjB,EAAYS,KAClD,IAAf3B,EAAIK,OACRL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOG,GACtB,IAAf9B,EAAIK,OACfL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKG,GAErD9B,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKT,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJnC,EAAO,2BAA4BmC,EAAMM,SAClCjB,EAAMW,KAGdnC,EAAO,0CADP2B,GAAS,EACgDG,GACpDC,EAAM,EACHE,IAEHN,IAAUG,GACd9B,EAAO,qCACAwB,EAAM,KAAME,SAFpB,EAIA,CACF,CCKST,CAAOK,EAAYC,EAASlB,EAAME,GAUzC,SAAe4B,EAAOT,GACrB,GAAKS,EACJ,OAAOX,EAAMW,GAEdX,EAAM,KAAME,EACZ,GACD,CACF,CE1EA,SAASgB,EAAkBpB,EAAYC,EAASpB,EAASC,EAAKoB,GAC7D,GAAKhB,UAAUC,OAAS,EACvB,OAAOP,EAASC,EAATD,CAAoBoB,EAAYC,EAASnB,GAEjDF,EAASC,EAASC,EAAlBF,CAAyBoB,EAAYC,EAASC,EAC/C,CClBAmB,EAAAC,EAAA,UAAA1C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index b18992d..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 0423d00eec497bd9f428c1a572651b24ac6c2494 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 08:26:11 +0000 Subject: [PATCH 106/147] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 ---- .github/workflows/publish.yml | 249 -- .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 132 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 229 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.factory.js | 73 - benchmark/benchmark.js | 160 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 224 - docs/types/test.ts | 166 - examples/index.js | 55 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 164 - lib/index.js | 77 - lib/limit.js | 142 - lib/main.js | 95 - lib/validate.js | 80 - package.json | 65 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 1095 ----- test/test.js | 38 - test/test.main.js | 1035 ----- test/test.validate.js | 181 - 50 files changed, 4873 insertions(+), 6953 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/limit.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 547b820..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-03-01T03:09:33.188Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1e08946..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 5358060..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index fa37f2d..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '37 1 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9106b5d..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -460,7 +457,7 @@ reduceRightAsync( files, acc, read, done ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -531,11 +528,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right +[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right/tree/esm -[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce +[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index b155fd2..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var reduceRightAsync; - var arr; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - reduceRightAsync = factory( onItem ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - var acc; - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index af5c346..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var reduceRightAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=false', function benchmark( b ) { - var opts; - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'series': false - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var arr; - var len; - var acc; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'limit': 3 - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b8adcd2..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right" -%% click B href "https://github.com/stdlib-js/utils-async-reduce-right/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-reduce-right/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-reduce-right/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-reduce-right/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right -[production-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-async-reduce-right/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-async-reduce-right/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-async-reduce-right/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 47a072e..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import reduceRightAsync from '../docs/types/index'; -export = reduceRightAsync; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 530ca4d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var c=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var x=c(function(U,O){ -var R=require('@stdlib/assert-is-plain-object/dist'),h=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,k=require('@stdlib/assert-is-positive-integer/dist').isPrimitive,d=require('@stdlib/error-tools-fmtprodmsg/dist');function I(e,r){return R(r)?(h(r,"thisArg")&&(e.thisArg=r.thisArg),h(r,"series")&&(e.series=r.series,!j(e.series))?new TypeError(d('1RZ2o',"series",e.series)):h(r,"limit")&&(e.limit=r.limit,!k(e.limit))?new TypeError(d('1RZ3P',"limit",e.limit)):null):new TypeError(d('1RZ2V',r));}O.exports=I -});var P=c(function(W,E){ -var J=require("debug"),a=J("reduce-right-async:limit");function L(e,r,i,t,s){var f,m,v,n,u,g;if(n=e.length,a("Collection length: %d",n),n===0)return a("Finished processing a collection."),s(null,r);for(n0&&o();function o(){u-=1,a("Collection element %d: %s.",u,JSON.stringify(e[u])),t.length===3?t.call(i.thisArg,r,e[u],l):t.length===4?t.call(i.thisArg,r,e[u],u,l):t.call(i.thisArg,r,e[u],u,e,l);function l(w,A){if(!m){if(w)return m=!0,b(w);a("Accumulator: %s",JSON.stringify(A)),r=A,b()}}}function b(l){if(l)return a("Encountered an error: %s",l.message),s(l);if(f+=1,a("Processed %d of %d collection elements.",f,n),u>0)return o();if(f===n)return a("Finished processing a collection."),s(null,r)}}E.exports=L -});var q=c(function(X,F){ -var T=require('@stdlib/assert-is-function/dist'),S=require('@stdlib/assert-is-collection/dist'),y=require('@stdlib/error-tools-fmtprodmsg/dist'),B=require('@stdlib/constants-float64-pinf/dist'),z=x(),D=P();function G(e,r){var i,t,s;if(i={},arguments.length>1){if(t=z(i,e),t)throw t;s=r}else s=e;if(!T(s))throw new TypeError(y('1RZ3q',s));return i.series===void 0&&i.limit===void 0&&(i.series=!0),i.series?i.limit=1:i.limit||(i.limit=B),f;function f(m,v,n){if(!S(m))throw new TypeError(y('1RZAh',m));if(!T(n))throw new TypeError(y('1RZ3q',n));return D(m,v,i,s,u);function u(g,o){if(g)return n(g);n(null,o)}}}F.exports=G -});var N=c(function(Y,C){ -var p=q();function H(e,r,i,t,s){if(arguments.length<5)return p(i)(e,r,t);p(i,t)(e,r,s)}C.exports=H -});var K=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),V=N(),M=q();K(V,"factory",M);module.exports=V; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index acb9d67..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/limit.js", "../lib/factory.js", "../lib/main.js", "../lib/index.js"], - "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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\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 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 to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\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 === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, 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 ( !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, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\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* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nmodule.exports = reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' );\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, 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"], - "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,0BAA2B,EAkB/C,SAASE,EAAOC,EAAYC,EAAKC,EAAMC,EAAKC,EAAO,CAClD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMR,EAAW,OACjBF,EAAO,wBAAyBU,CAAI,EAE/BA,IAAQ,EACZ,OAAAV,EAAO,mCAAoC,EACpCM,EAAM,KAAMH,CAAI,EAYxB,IAVKO,EAAMN,EAAK,MACfK,EAAMC,EAEND,EAAML,EAAK,MAEZJ,EAAO,wBAAyBS,CAAI,EACpCT,EAAO,0BAA2BK,EAAI,MAAO,EAE7CE,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVE,EAAK,EAQP,SAASA,GAAO,CACfF,GAAO,EACPX,EAAO,6BAA8BW,EAAK,KAAK,UAAWT,EAAYS,CAAI,CAAE,CAAE,EACzEN,EAAI,SAAW,EACnBA,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGG,CAAG,EACxCT,EAAI,SAAW,EAC1BA,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGA,EAAKG,CAAG,EAExDT,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGA,EAAKT,EAAYY,CAAG,EAUrE,SAASA,EAAIC,EAAOC,EAAS,CAC5B,GAAK,CAAAR,EAIL,IAAKO,EACJ,OAAAP,EAAM,GACCS,EAAMF,CAAM,EAEpBf,EAAO,kBAAmB,KAAK,UAAWgB,CAAO,CAAE,EACnDb,EAAMa,EACNC,EAAK,EACN,CACD,CASA,SAASA,EAAMF,EAAQ,CACtB,GAAKA,EACJ,OAAAf,EAAO,2BAA4Be,EAAM,OAAQ,EAC1CT,EAAMS,CAAM,EAIpB,GAFAR,GAAS,EACTP,EAAO,0CAA2CO,EAAOG,CAAI,EACxDC,EAAM,EACV,OAAOE,EAAK,EAEb,GAAKN,IAAUG,EACd,OAAAV,EAAO,mCAAoC,EACpCM,EAAM,KAAMH,CAAI,CAEzB,CACD,CAKAL,EAAO,QAAUG,IC7IjB,IAAAiB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,gCAAiC,EACjDC,EAAW,IACXC,EAAQ,IAoEZ,SAASC,EAASC,EAASC,EAAM,CAChC,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,CAACP,EAAYW,CAAE,EACnB,MAAM,IAAI,UAAWT,EAAQ,mEAAoES,CAAE,CAAE,EAEtG,OAAKF,EAAK,SAAW,QAAUA,EAAK,QAAU,SAC7CA,EAAK,OAAS,IAEVA,EAAK,OACTA,EAAK,MAAQ,EACDA,EAAK,QACjBA,EAAK,MAAQN,GAEPS,EAaP,SAASA,EAAkBC,EAAYC,EAASC,EAAO,CACtD,GAAK,CAACd,EAAcY,CAAW,EAC9B,MAAM,IAAI,UAAWX,EAAQ,sEAAuEW,CAAW,CAAE,EAElH,GAAK,CAACb,EAAYe,CAAK,EACtB,MAAM,IAAI,UAAWb,EAAQ,mEAAoEa,CAAK,CAAE,EAEzG,OAAOV,EAAOQ,EAAYC,EAASL,EAAME,EAAGK,CAAK,EAUjD,SAASA,EAAMC,EAAOC,EAAM,CAC3B,GAAKD,EACJ,OAAOF,EAAME,CAAM,EAEpBF,EAAM,KAAMG,CAAI,CACjB,CACD,CACD,CAKAnB,EAAO,QAAUO,ICnKjB,IAAAa,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,IA8Dd,SAASC,EAAkBC,EAAYC,EAASC,EAASC,EAAKC,EAAO,CACpE,GAAK,UAAU,OAAS,EACvB,OAAON,EAASI,CAAQ,EAAGF,EAAYC,EAASE,CAAI,EAErDL,EAASI,EAASC,CAAI,EAAGH,EAAYC,EAASG,CAAK,CACpD,CAKAP,EAAO,QAAUE,IC9BjB,IAAIM,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "isPositiveInteger", "format", "validate", "opts", "options", "require_limit", "__commonJSMin", "exports", "module", "logger", "debug", "limit", "collection", "acc", "opts", "fcn", "done", "count", "flg", "lim", "len", "idx", "i", "next", "cb", "error", "result", "clbk", "require_factory", "__commonJSMin", "exports", "module", "isFunction", "isCollection", "format", "PINF", "validate", "limit", "factory", "options", "fcn", "opts", "err", "f", "reduceRightAsync", "collection", "initial", "done", "clbk", "error", "acc", "require_main", "__commonJSMin", "exports", "module", "factory", "reduceRightAsync", "collection", "initial", "options", "fcn", "done", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3f22669..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,224 +0,0 @@ - -{{alias}}( collection, initial, [options,] reducer, done ) - Applies a function against an accumulator and each element in a collection - and returns the accumulated result, iterating from right to left. - - When invoked, `reducer` is provided a maximum of five arguments: - - - `accumulator`: accumulated value - - `value`: collection value - - `index`: collection index - - `collection`: the input collection - - `next`: a callback to be invoked after processing a collection `value` - - The actual number of provided arguments depends on function length. If - `reducer` accepts three arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `next` - - If `reducer` accepts four arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `index` - - `next` - - For every other `reducer` signature, `reducer` is provided all five - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `accumulator`: accumulated value - - If a provided function calls the `next` callback with a truthy `error` - argument, the function suspends execution and immediately calls the `done` - callback for subsequent `error` handling. - - Execution is *not* guaranteed to be asynchronous. To guarantee asynchrony, - 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`). - - The function does not support dynamic collection resizing. - - If provided an empty collection, the function invokes the `done` callback - with the `initial` value as the second argument. - - The function does not skip `undefined` elements. - - When processing collection elements concurrently, *beware* of race - conditions when updating an accumulator. This is especially true when an - accumulator is a primitive (e.g., a number). In general, prefer object - accumulators. - - Parameters - ---------- - collection: Array|TypedArray|Object - Input collection over which to iterate. If provided an object, the - object must be array-like (excluding strings and functions). - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - reducer: Function - The function to invoke for each element in a collection. - - done: Function - A callback invoked either upon processing all collection elements or - upon encountering an error. - - Examples - -------- - // Basic usage: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, fcn, done ) - 3000 - 2500 - 1000 - 6500 - - // Limit number of concurrent invocations: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'limit': 2 }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 2500 - 3000 - 1000 - 6500 - - // Process concurrently: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'series': false }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 1000 - 2500 - 3000 - 6500 - - -{{alias}}.factory( [options,] fcn ) - Returns a function which applies a function against an accumulator and each - element in a collection and returns the accumulated result, iterating from - right to left. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - fcn: Function - The function to invoke for each element in a collection. - - Returns - ------- - out: Function - A function which invokes a function for each element in a collection. - - Examples - -------- - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > var opts = { 'series': false }; - > var f = {{alias}}.factory( opts, fcn ); - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > f( arr, acc, done ) - 1000 - 2500 - 3000 - 6500 - > acc = { 'sum': 0 }; - > arr = [ 1000, 1500, 2000 ]; - > f( arr, acc, done ) - 1000 - 1500 - 2000 - 4500 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0455864..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,166 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unsafe-assignment */ - -import reduceRightAsync = require( './index' ); - -const reducer = ( acc: any, value: number, index: number, next: Function ) => { - acc.sum += value; - if ( index === void 0 ) { - throw new Error( '`index` is missing.' ); - } - next( null, acc ); -}; - -const done = ( error: Error | null, acc: any ) => { - if ( error ) { - throw error; - } - if ( acc === void 0 ) { - throw new Error( '`acc` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( 2, acc, reducer, done ); // $ExpectError - reduceRightAsync( false, acc, reducer, done ); // $ExpectError - reduceRightAsync( true, acc, reducer, done ); // $ExpectError - reduceRightAsync( {}, acc, reducer, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a predicate argument which is not a predicate function... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 2, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, false, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, true, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 'abc', done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, [], done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a done callback argument which is not a function having a supported signature... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 2 ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, false ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, true ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 'abc' ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, {} ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, [] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const acc = { 'sum': 0 }; - reduceRightAsync(); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, reducer, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - reduceRightAsync.factory( reducer ); // $ExpectType FactoryFunction - reduceRightAsync.factory( { 'series': true }, reducer ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - reduceRightAsync.factory( [], reducer ); // $ExpectError - reduceRightAsync.factory( 123, reducer ); // $ExpectError - reduceRightAsync.factory( 'abc', reducer ); // $ExpectError - reduceRightAsync.factory( false, reducer ); // $ExpectError - reduceRightAsync.factory( true, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not a predicate function... -{ - reduceRightAsync.factory( {} ); // $ExpectError - reduceRightAsync.factory( true ); // $ExpectError - reduceRightAsync.factory( false ); // $ExpectError - reduceRightAsync.factory( {}, 123 ); // $ExpectError - reduceRightAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1( 12, acc, done ); // $ExpectError - fcn1( true, acc, done ); // $ExpectError - fcn1( false, acc, done ); // $ExpectError - fcn1( {}, acc, done ); // $ExpectError - - fcn1( [ 3000, 2500, 1000 ], acc, 12 ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, true ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, false ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, '5' ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, {} ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, [] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1(); // $ExpectError - fcn1( [ 3000, 2500, 1000 ] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - reduceRightAsync.factory( { 'limit': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': true }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': false }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - reduceRightAsync.factory( { 'series': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': 12 }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - reduceRightAsync.factory(); // $ExpectError - reduceRightAsync.factory( {}, reducer, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index dd64345..0000000 --- a/examples/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var resolve = require( 'path' ).resolve; -var readFile = require( '@stdlib/fs-read-file' ); -var reduceRightAsync = require( './../lib' ); - -var files = [ - resolve( __dirname, '..', 'package.json' ), - resolve( __dirname, '..', 'README.md' ) -]; - -function done( error, acc ) { - if ( error ) { - throw error; - } - console.log( acc.count ); -} - -function read( acc, file, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( file, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( null, acc ); - } - acc.count += 1; - next( null, acc ); - } -} - -var acc = { - 'count': 0 -}; -reduceRightAsync( files, acc, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 28e0a36..f6cba5d 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..ab01fae --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import{isPrimitive as c}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.1-esm/index.mjs";function m(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var d=m(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function f(e,m){var f,u,p;if(f={},arguments.length>1){if(u=function(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("1RZ2o","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!c(e.limit))?new TypeError(r("1RZ3P","limit",e.limit)):null):new TypeError(r("1RZ2V",t))}(f,e),u)throw u;p=m}else p=e;if(!t(p))throw new TypeError(r("1RZ3q",p));return void 0===f.series&&void 0===f.limit&&(f.series=!0),f.series?f.limit=1:f.limit||(f.limit=s),function(e,s,n){if(!i(e))throw new TypeError(r("1RZAh",e));if(!t(n))throw new TypeError(r("1RZ3q",n));return function(e,t,i,r,s){var n,o,l,c,m,f;if(c=e.length,d("Collection length: %d",c),0===c)return d("Finished processing a collection."),s(null,t);for(l=c0&&u();function u(){function s(e,i){if(!o){if(e)return o=!0,p(e);d("Accumulator: %s",JSON.stringify(i)),t=i,p()}}d("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function p(e){return e?(d("Encountered an error: %s",e.message),s(e)):(d("Processed %d of %d collection elements.",n+=1,c),m>0?u():n===c?(d("Finished processing a collection."),s(null,t)):void 0)}}(e,s,f,p,(function(e,t){if(e)return n(e);n(null,t)}))}}function u(e,t,i,r,s){if(arguments.length<5)return f(i)(e,t,r);f(i,r)(e,t,s)}e(u,"factory",f);export{u as default,f as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..e11f2cb --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/limit.js","../lib/factory.js","../lib/validate.js","../lib/main.js","../lib/index.js"],"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 logger = require( 'debug' );\n\n\n// VARIABLES //\n\nvar debug = logger( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RZ3q', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '1RZAh', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RZ3q', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '1RZ2V', 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( '1RZ2o', '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( '1RZ3P', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["debug","logger","factory","options","fcn","opts","err","f","arguments","length","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","validate","isFunction","PINF","collection","initial","done","isCollection","acc","count","flg","lim","len","idx","i","next","cb","error","result","clbk","JSON","stringify","call","message","reduceRightAsync","setReadOnly","main"],"mappings":";;81CA2BIA,uDAAQC,CAAQ,4BCoEpB,SAASC,EAASC,EAASC,GAC1B,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAA,EACFG,UAAUC,OAAS,EAAI,CAE3B,GADAH,EChDF,SAAmBD,EAAMF,GACxB,OAAMO,EAAUP,IAGXQ,EAAYR,EAAS,aACzBE,EAAKO,QAAUT,EAAQS,SAEnBD,EAAYR,EAAS,YACzBE,EAAKQ,OAASV,EAAQU,QAChBC,EAAWT,EAAKQ,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUX,EAAKQ,SAGnDF,EAAYR,EAAS,WACzBE,EAAKY,MAAQd,EAAQc,OACfC,EAAmBb,EAAKY,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASX,EAAKY,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASb,GAkBzC,CD4BQgB,CAAUd,EAAMF,GACjBG,EACJ,MAAMA,EAEPC,EAAIH,CACN,MACEG,EAAIJ,EAEL,IAAMiB,EAAYb,GACjB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAUvC,YARqB,IAAhBF,EAAKQ,aAAoC,IAAfR,EAAKY,QACnCZ,EAAKQ,QAAS,GAEVR,EAAKQ,OACTR,EAAKY,MAAQ,EACDZ,EAAKY,QACjBZ,EAAKY,MAAQI,GAed,SAA2BC,EAAYC,EAASC,GAC/C,IAAMC,EAAcH,GACnB,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,IAAMF,EAAYI,GACjB,MAAM,IAAIT,UAAWC,EAAQ,QAASQ,IAEvC,ODhGF,SAAgBF,EAAYI,EAAKrB,EAAMD,EAAKoB,GAC3C,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMR,EAAWb,OACjBT,EAAO,wBAAyB8B,GAEnB,IAARA,EAEJ,OADA9B,EAAO,qCACAwB,EAAM,KAAME,GAYpB,IATCG,EADIC,EAAMzB,EAAKY,MACTa,EAEAzB,EAAKY,MAEZjB,EAAO,wBAAyB6B,GAChC7B,EAAO,0BAA2BI,EAAIK,QAEtCkB,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVE,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKR,EAAL,CAIA,GAAKO,EAEJ,OADAP,GAAM,EACCS,EAAMF,GAEdnC,EAAO,kBAAmBsC,KAAKC,UAAWH,IAC1CV,EAAMU,EACNC,GAPC,CAQD,CA5BDrC,EAAO,6BADP+B,GAAO,EACmCO,KAAKC,UAAWjB,EAAYS,KAClD,IAAf3B,EAAIK,OACRL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOG,GACtB,IAAf9B,EAAIK,OACfL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKG,GAErD9B,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKT,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJnC,EAAO,2BAA4BmC,EAAMM,SAClCjB,EAAMW,KAGdnC,EAAO,0CADP2B,GAAS,EACgDG,GACpDC,EAAM,EACHE,IAEHN,IAAUG,GACd9B,EAAO,qCACAwB,EAAM,KAAME,SAFpB,EAIA,CACF,CCKST,CAAOK,EAAYC,EAASlB,EAAME,GAUzC,SAAe4B,EAAOT,GACrB,GAAKS,EACJ,OAAOX,EAAMW,GAEdX,EAAM,KAAME,EACZ,GACD,CACF,CE1EA,SAASgB,EAAkBpB,EAAYC,EAASpB,EAASC,EAAKoB,GAC7D,GAAKhB,UAAUC,OAAS,EACvB,OAAOP,EAASC,EAATD,CAAoBoB,EAAYC,EAASnB,GAEjDF,EAASC,EAASC,EAAlBF,CAAyBoB,EAAYC,EAASC,EAC/C,CClBAmB,EAAAC,EAAA,UAAA1C"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index e107128..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,164 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var validate = require( './validate.js' ); -var limit = require( './limit.js' ); - - -// MAIN // - -/** -* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} last argument must be a function -* @returns {Function} function which invokes the provided function once for each element in a collection -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error, data ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var opts = { -* 'series': false -* }; -* -* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: -* var reduceRightAsync = factory( opts, read ); -* -* // Create a collection over which to iterate: -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* // Define a callback which handles errors: -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* // Run `read` for each element in `files`: -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, done ); -*/ -function factory( options, fcn ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = fcn; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '1RZ3q', f ) ); - } - if ( opts.series === void 0 && opts.limit === void 0 ) { - opts.series = true; - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return reduceRightAsync; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * @private - * @param {Collection} collection - input collection - * @param {*} initial - initial value - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be a collection - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function reduceRightAsync( collection, initial, done ) { - if ( !isCollection( collection ) ) { - throw new TypeError( format( '1RZAh', collection ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '1RZ3q', done ) ); - } - return limit( collection, initial, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {*} [acc] - accumulated value - * @returns {void} - */ - function clbk( error, acc ) { - if ( error ) { - return done( error ); - } - done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ae657ff..0000000 --- a/lib/index.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* @module @stdlib/utils-async-reduce-right -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' ); -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/limit.js b/lib/limit.js deleted file mode 100644 index cdb60af..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); - - -// VARIABLES // - -var debug = logger( 'reduce-right-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each element in a collection, limiting the number of concurrently pending functions and iterating from right to left. -* -* @private -* @param {Collection} collection - input collection -* @param {*} acc - initial value -* @param {Options} opts - function options -* @param {*} [opts.thisArg] - execution context -* @param {PositiveInteger} [opts.limit] - maximum number of pending function invocations -* @param {Function} fcn - function to invoke -* @param {Callback} done - function to invoke upon completion or upon encountering an error -* @returns {void} -*/ -function limit( collection, acc, opts, fcn, done ) { - var count; - var flg; - var lim; - var len; - var idx; - var i; - - len = collection.length; - debug( 'Collection length: %d', len ); - - if ( len === 0 ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - count = 0; - idx = len; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all collection elements... - if ( idx > 0 ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next element in a collection. - * - * @private - */ - function next() { - idx -= 1; - debug( 'Collection element %d: %s.', idx, JSON.stringify( collection[ idx ] ) ); - if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], cb ); - } else if ( fcn.length === 4 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, cb ); - } else { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len - } - /** - * Callback invoked once a provided function finishes processing a collection element. - * - * @private - * @param {*} [error] - error - * @param {*} [result] - accumulation result - * @returns {void} - */ - function cb( error, result ) { - if ( flg ) { - // Prevent further processing of collection elements: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Accumulator: %s', JSON.stringify( result ) ); - acc = result; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next collection element. - * - * @private - * @param {*} [error] - error - * @returns {void} - */ - function clbk( error ) { - if ( error ) { - debug( 'Encountered an error: %s', error.message ); - return done( error ); - } - count += 1; - debug( 'Processed %d of %d collection elements.', count, len ); - if ( idx > 0 ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index c8b0d0f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param {Collection} collection - input collection -* @param {*} initial - initial value -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} second-to-last argument must be a function -* @throws {TypeError} last argument must be a function -* @returns {void} -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -function reduceRightAsync( collection, initial, options, fcn, done ) { - if ( arguments.length < 5 ) { - return factory( options )( collection, initial, fcn ); - } - factory( options, fcn )( collection, initial, done ); -} - - -// EXPORTS // - -module.exports = reduceRightAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 0c666fe..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @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 -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'thisArg': {}, -* 'series': false, -* 'limit': 10 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '1RZ2V', options ) ); - } - if ( hasOwnProp( options, 'thisArg' ) ) { - opts.thisArg = options.thisArg; - } - if ( hasOwnProp( options, 'series' ) ) { - opts.series = options.series; - if ( !isBoolean( opts.series ) ) { - return new TypeError( format( '1RZ2o', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '1RZ3P', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index eaf0e2f..3464c63 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,44 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-boolean": "^0.2.1", - "@stdlib/assert-is-collection": "^0.2.1", - "@stdlib/assert-is-function": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/assert-is-positive-integer": "^0.2.1", - "@stdlib/constants-float64-pinf": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", - "debug": "^2.6.9", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/constants-float64-eps": "^0.2.1", - "@stdlib/fs-read-file": "^0.2.1", - "@stdlib/utils-noop": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..9a829df --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 8244931..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1095 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( {}, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, next ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - factory( opts, next ); - }; - } -}); - -tape( 'the function returns a function (no options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided a collection (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a collection (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (1 argument)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (2 arguments)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with five arguments', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn() { - var value; - var next; - var acc; - var k; - - acc = arguments[ 0 ]; - value = arguments[ 1 ]; - k = arguments[ 2 ]; - next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( k, i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the returned function supports processing collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements concurrently', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 100, 250, 300 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements sequentially (limit = 1)', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of collection elements which are processed at any one time', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 250, 300, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 250, 100, 300 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var reduceRightAsync; - var arr; - - reduceRightAsync = factory( fcn ); - arr = []; - - reduceRightAsync( arr, 0, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var reduceRightAsync; - var obj; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = []; - obj = {}; - reduceRightAsync( arr, obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - i = 0; - - reduceRightAsync( arr, {}, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, acc ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the returned function does not skip empty elements', function test( t ) { - var reduceRightAsync; - var expected; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index f273a40..0000000 --- a/test/test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof reduceRightAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 1893240..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1035 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a collection', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (no options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, next, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, 0 ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - reduceRightAsync( [ 1, 2, 3 ], 0, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (1 argument)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (2 arguments)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with five arguments', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn() { - var next; - var acc; - var v; - - next = arguments[ 4 ]; - acc = arguments[ 0 ]; - v = arguments[ 1 ]; - - i -= 1; - j += 1; - - t.strictEqual( v, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, v ); - - function onTimeout() { - acc.sum += v; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'by default, the function processes collection elements sequentially', function test( t ) { - var values; - var count; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements concurrently', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 100, 250, 300 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': true - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially (limit = 1)', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var arr; - var ctx; - - arr = [ 3, 2, 1 ]; - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 3, 2, 1 ]; - opts = { - 'series': true - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 250, 100, 300 ]; - opts = { - 'limit': 2 - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var arr = []; - reduceRightAsync( arr, 0, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var arr = []; - var obj = {}; - - reduceRightAsync( arr, obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - arr = [ 3, 2, 1 ]; - i = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, value ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the function does not skip empty elements', function test( t ) { - var expected; - var arr; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, fcn, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 7660838..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,181 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `limit` option which is not a positive integer', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - -5, - 0, - 3.14, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'limit': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `series` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'series': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function accepts any value for the `thisArg` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'thisArg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err, null, 'returns null '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'thisArg': {}, - 'series': false, - 'limit': 10 - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From 1d29c8cfd11fb1ad82d4edd31e1f6ada243e7aa6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 03:51:17 +0000 Subject: [PATCH 107/147] Transform error messages --- lib/factory.js | 8 ++++---- lib/validate.js | 8 ++++---- package.json | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 1125052..e107128 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -22,7 +22,7 @@ var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var PINF = require( '@stdlib/constants-float64-pinf' ); var validate = require( './validate.js' ); var limit = require( './limit.js' ); @@ -109,7 +109,7 @@ function factory( options, fcn ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '1RZ3q', f ) ); } if ( opts.series === void 0 && opts.limit === void 0 ) { opts.series = true; @@ -134,10 +134,10 @@ function factory( options, fcn ) { */ function reduceRightAsync( collection, initial, done ) { if ( !isCollection( collection ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a collection. Value: `%s`.', collection ) ); + throw new TypeError( format( '1RZAh', collection ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '1RZ3q', done ) ); } return limit( collection, initial, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index 9ba927e..0c666fe 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,7 +54,7 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '1RZ2V', options ) ); } if ( hasOwnProp( options, 'thisArg' ) ) { opts.thisArg = options.thisArg; @@ -62,13 +62,13 @@ function validate( opts, options ) { if ( hasOwnProp( options, 'series' ) ) { opts.series = options.series; if ( !isBoolean( opts.series ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'series', opts.series ) ); + return new TypeError( format( '1RZ2o', 'series', opts.series ) ); } } if ( hasOwnProp( options, 'limit' ) ) { opts.limit = options.limit; if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'limit', opts.limit ) ); + return new TypeError( format( '1RZ3P', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index 31e9a96..eaf0e2f 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-plain-object": "^0.2.1", "@stdlib/assert-is-positive-integer": "^0.2.1", "@stdlib/constants-float64-pinf": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", "debug": "^2.6.9", From dfb9e4e66245509f12b3f3a9a207e48e74d97656 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 08:12:12 +0000 Subject: [PATCH 108/147] Remove files --- index.d.ts | 410 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5257 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index f6cba5d..0000000 --- a/index.d.ts +++ /dev/null @@ -1,410 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Execution context. - */ - thisArg?: ThisParameterType>; - - /** - * The maximum number of pending invocations at any one time. - */ - limit?: number; - - /** - * Boolean indicating whether to sequentially invoke the reducer function for each `collection` element. If `true`, the function sets `options.limit=1`. Default: true. - */ - series?: boolean; -} - -/** -* Callback function. -*/ -type Nullary = () => void; - -/** -* Callback function. -* -* @param error - encountered error or null -*/ -type Unary = ( error: Error | null ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Binary = ( error: Error | null, accumulator: U ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param next - a callback to be invoked after processing a collection `value` -*/ -type TernaryReducer = ( this: V, accumulator: U, value: T, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuaternaryReducer = ( this: V, accumulator: U, value: T, index: number, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuinaryReducer = ( this: V, accumulator: U, value: T, index: number, collection: Collection, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type Reducer = TernaryReducer | QuaternaryReducer | QuinaryReducer; - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result. -* -* @param collection - input collection -* @param initial - initial value -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( collection: Collection, initial: U, done: Callback ) => void; - -/** -* Interface for `reduceRightAsync`. -*/ -interface ReduceRightAsync { - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, {}, read, done ); - */ - ( collection: Collection, initial: U, options: Options, reducer: Reducer, done: Callback ): void; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, read, done ); - */ - ( collection: Collection, initial: U, reducer: Reducer, done: Callback ): void; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @throws must provide valid options - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var opts = { - * 'series': false - * }; - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( opts, read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( options: Options, reducer: Reducer ): FactoryFunction; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param reducer - function to invoke for each element in a collection - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( reducer: Reducer ): FactoryFunction; -} - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param collection - input collection -* @param initial - initial value -* @param options - function options -* @param options.thisArg - execution context -* @param options.limit - maximum number of pending invocations at any one time -* @param 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 (default: true) -* @param reducer - function to invoke for each element in a collection -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -declare var reduceRightAsync: ReduceRightAsync; - - -// EXPORTS // - -export = reduceRightAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index ab01fae..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import{isPrimitive as c}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.1-esm/index.mjs";function m(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var d=m(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function f(e,m){var f,u,p;if(f={},arguments.length>1){if(u=function(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("1RZ2o","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!c(e.limit))?new TypeError(r("1RZ3P","limit",e.limit)):null):new TypeError(r("1RZ2V",t))}(f,e),u)throw u;p=m}else p=e;if(!t(p))throw new TypeError(r("1RZ3q",p));return void 0===f.series&&void 0===f.limit&&(f.series=!0),f.series?f.limit=1:f.limit||(f.limit=s),function(e,s,n){if(!i(e))throw new TypeError(r("1RZAh",e));if(!t(n))throw new TypeError(r("1RZ3q",n));return function(e,t,i,r,s){var n,o,l,c,m,f;if(c=e.length,d("Collection length: %d",c),0===c)return d("Finished processing a collection."),s(null,t);for(l=c0&&u();function u(){function s(e,i){if(!o){if(e)return o=!0,p(e);d("Accumulator: %s",JSON.stringify(i)),t=i,p()}}d("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function p(e){return e?(d("Encountered an error: %s",e.message),s(e)):(d("Processed %d of %d collection elements.",n+=1,c),m>0?u():n===c?(d("Finished processing a collection."),s(null,t)):void 0)}}(e,s,f,p,(function(e,t){if(e)return n(e);n(null,t)}))}}function u(e,t,i,r,s){if(arguments.length<5)return f(i)(e,t,r);f(i,r)(e,t,s)}e(u,"factory",f);export{u as default,f as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index e11f2cb..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/limit.js","../lib/factory.js","../lib/validate.js","../lib/main.js","../lib/index.js"],"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 logger = require( 'debug' );\n\n\n// VARIABLES //\n\nvar debug = logger( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RZ3q', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '1RZAh', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RZ3q', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '1RZ2V', 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( '1RZ2o', '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( '1RZ3P', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["debug","logger","factory","options","fcn","opts","err","f","arguments","length","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","validate","isFunction","PINF","collection","initial","done","isCollection","acc","count","flg","lim","len","idx","i","next","cb","error","result","clbk","JSON","stringify","call","message","reduceRightAsync","setReadOnly","main"],"mappings":";;81CA2BIA,uDAAQC,CAAQ,4BCoEpB,SAASC,EAASC,EAASC,GAC1B,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAA,EACFG,UAAUC,OAAS,EAAI,CAE3B,GADAH,EChDF,SAAmBD,EAAMF,GACxB,OAAMO,EAAUP,IAGXQ,EAAYR,EAAS,aACzBE,EAAKO,QAAUT,EAAQS,SAEnBD,EAAYR,EAAS,YACzBE,EAAKQ,OAASV,EAAQU,QAChBC,EAAWT,EAAKQ,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUX,EAAKQ,SAGnDF,EAAYR,EAAS,WACzBE,EAAKY,MAAQd,EAAQc,OACfC,EAAmBb,EAAKY,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASX,EAAKY,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASb,GAkBzC,CD4BQgB,CAAUd,EAAMF,GACjBG,EACJ,MAAMA,EAEPC,EAAIH,CACN,MACEG,EAAIJ,EAEL,IAAMiB,EAAYb,GACjB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAUvC,YARqB,IAAhBF,EAAKQ,aAAoC,IAAfR,EAAKY,QACnCZ,EAAKQ,QAAS,GAEVR,EAAKQ,OACTR,EAAKY,MAAQ,EACDZ,EAAKY,QACjBZ,EAAKY,MAAQI,GAed,SAA2BC,EAAYC,EAASC,GAC/C,IAAMC,EAAcH,GACnB,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,IAAMF,EAAYI,GACjB,MAAM,IAAIT,UAAWC,EAAQ,QAASQ,IAEvC,ODhGF,SAAgBF,EAAYI,EAAKrB,EAAMD,EAAKoB,GAC3C,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMR,EAAWb,OACjBT,EAAO,wBAAyB8B,GAEnB,IAARA,EAEJ,OADA9B,EAAO,qCACAwB,EAAM,KAAME,GAYpB,IATCG,EADIC,EAAMzB,EAAKY,MACTa,EAEAzB,EAAKY,MAEZjB,EAAO,wBAAyB6B,GAChC7B,EAAO,0BAA2BI,EAAIK,QAEtCkB,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVE,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKR,EAAL,CAIA,GAAKO,EAEJ,OADAP,GAAM,EACCS,EAAMF,GAEdnC,EAAO,kBAAmBsC,KAAKC,UAAWH,IAC1CV,EAAMU,EACNC,GAPC,CAQD,CA5BDrC,EAAO,6BADP+B,GAAO,EACmCO,KAAKC,UAAWjB,EAAYS,KAClD,IAAf3B,EAAIK,OACRL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOG,GACtB,IAAf9B,EAAIK,OACfL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKG,GAErD9B,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKT,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJnC,EAAO,2BAA4BmC,EAAMM,SAClCjB,EAAMW,KAGdnC,EAAO,0CADP2B,GAAS,EACgDG,GACpDC,EAAM,EACHE,IAEHN,IAAUG,GACd9B,EAAO,qCACAwB,EAAM,KAAME,SAFpB,EAIA,CACF,CCKST,CAAOK,EAAYC,EAASlB,EAAME,GAUzC,SAAe4B,EAAOT,GACrB,GAAKS,EACJ,OAAOX,EAAMW,GAEdX,EAAM,KAAME,EACZ,GACD,CACF,CE1EA,SAASgB,EAAkBpB,EAAYC,EAASpB,EAASC,EAAKoB,GAC7D,GAAKhB,UAAUC,OAAS,EACvB,OAAOP,EAASC,EAATD,CAAoBoB,EAAYC,EAASnB,GAEjDF,EAASC,EAASC,EAAlBF,CAAyBoB,EAAYC,EAASC,EAC/C,CClBAmB,EAAAC,EAAA,UAAA1C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 9a829df..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 10f4ededd50625fb491ed380b0e2094d00c87f49 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 08:12:23 +0000 Subject: [PATCH 109/147] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 ---- .github/workflows/publish.yml | 249 -- .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 132 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.factory.js | 73 - benchmark/benchmark.js | 160 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 224 - docs/types/test.ts | 166 - examples/index.js | 55 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 164 - lib/index.js | 77 - lib/limit.js | 142 - lib/main.js | 95 - lib/validate.js | 80 - package.json | 65 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 1095 ----- test/test.js | 38 - test/test.main.js | 1035 ----- test/test.validate.js | 181 - 50 files changed, 4873 insertions(+), 6956 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/limit.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 1fcb011..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-04-01T02:35:37.903Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1e08946..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 5358060..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index fa37f2d..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '37 1 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index ec90164..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -460,7 +457,7 @@ reduceRightAsync( files, acc, read, done ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -531,11 +528,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right +[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right/tree/esm -[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce +[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index b155fd2..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var reduceRightAsync; - var arr; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - reduceRightAsync = factory( onItem ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - var acc; - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index af5c346..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var reduceRightAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=false', function benchmark( b ) { - var opts; - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'series': false - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var arr; - var len; - var acc; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'limit': 3 - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b8adcd2..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right" -%% click B href "https://github.com/stdlib-js/utils-async-reduce-right/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-reduce-right/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-reduce-right/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-reduce-right/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right -[production-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-async-reduce-right/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-async-reduce-right/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-async-reduce-right/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 47a072e..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import reduceRightAsync from '../docs/types/index'; -export = reduceRightAsync; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 530ca4d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var c=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var x=c(function(U,O){ -var R=require('@stdlib/assert-is-plain-object/dist'),h=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,k=require('@stdlib/assert-is-positive-integer/dist').isPrimitive,d=require('@stdlib/error-tools-fmtprodmsg/dist');function I(e,r){return R(r)?(h(r,"thisArg")&&(e.thisArg=r.thisArg),h(r,"series")&&(e.series=r.series,!j(e.series))?new TypeError(d('1RZ2o',"series",e.series)):h(r,"limit")&&(e.limit=r.limit,!k(e.limit))?new TypeError(d('1RZ3P',"limit",e.limit)):null):new TypeError(d('1RZ2V',r));}O.exports=I -});var P=c(function(W,E){ -var J=require("debug"),a=J("reduce-right-async:limit");function L(e,r,i,t,s){var f,m,v,n,u,g;if(n=e.length,a("Collection length: %d",n),n===0)return a("Finished processing a collection."),s(null,r);for(n0&&o();function o(){u-=1,a("Collection element %d: %s.",u,JSON.stringify(e[u])),t.length===3?t.call(i.thisArg,r,e[u],l):t.length===4?t.call(i.thisArg,r,e[u],u,l):t.call(i.thisArg,r,e[u],u,e,l);function l(w,A){if(!m){if(w)return m=!0,b(w);a("Accumulator: %s",JSON.stringify(A)),r=A,b()}}}function b(l){if(l)return a("Encountered an error: %s",l.message),s(l);if(f+=1,a("Processed %d of %d collection elements.",f,n),u>0)return o();if(f===n)return a("Finished processing a collection."),s(null,r)}}E.exports=L -});var q=c(function(X,F){ -var T=require('@stdlib/assert-is-function/dist'),S=require('@stdlib/assert-is-collection/dist'),y=require('@stdlib/error-tools-fmtprodmsg/dist'),B=require('@stdlib/constants-float64-pinf/dist'),z=x(),D=P();function G(e,r){var i,t,s;if(i={},arguments.length>1){if(t=z(i,e),t)throw t;s=r}else s=e;if(!T(s))throw new TypeError(y('1RZ3q',s));return i.series===void 0&&i.limit===void 0&&(i.series=!0),i.series?i.limit=1:i.limit||(i.limit=B),f;function f(m,v,n){if(!S(m))throw new TypeError(y('1RZAh',m));if(!T(n))throw new TypeError(y('1RZ3q',n));return D(m,v,i,s,u);function u(g,o){if(g)return n(g);n(null,o)}}}F.exports=G -});var N=c(function(Y,C){ -var p=q();function H(e,r,i,t,s){if(arguments.length<5)return p(i)(e,r,t);p(i,t)(e,r,s)}C.exports=H -});var K=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),V=N(),M=q();K(V,"factory",M);module.exports=V; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index acb9d67..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/limit.js", "../lib/factory.js", "../lib/main.js", "../lib/index.js"], - "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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\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 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 to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\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 === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, 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 ( !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, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\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* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nmodule.exports = reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' );\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, 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"], - "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,0BAA2B,EAkB/C,SAASE,EAAOC,EAAYC,EAAKC,EAAMC,EAAKC,EAAO,CAClD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMR,EAAW,OACjBF,EAAO,wBAAyBU,CAAI,EAE/BA,IAAQ,EACZ,OAAAV,EAAO,mCAAoC,EACpCM,EAAM,KAAMH,CAAI,EAYxB,IAVKO,EAAMN,EAAK,MACfK,EAAMC,EAEND,EAAML,EAAK,MAEZJ,EAAO,wBAAyBS,CAAI,EACpCT,EAAO,0BAA2BK,EAAI,MAAO,EAE7CE,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVE,EAAK,EAQP,SAASA,GAAO,CACfF,GAAO,EACPX,EAAO,6BAA8BW,EAAK,KAAK,UAAWT,EAAYS,CAAI,CAAE,CAAE,EACzEN,EAAI,SAAW,EACnBA,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGG,CAAG,EACxCT,EAAI,SAAW,EAC1BA,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGA,EAAKG,CAAG,EAExDT,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGA,EAAKT,EAAYY,CAAG,EAUrE,SAASA,EAAIC,EAAOC,EAAS,CAC5B,GAAK,CAAAR,EAIL,IAAKO,EACJ,OAAAP,EAAM,GACCS,EAAMF,CAAM,EAEpBf,EAAO,kBAAmB,KAAK,UAAWgB,CAAO,CAAE,EACnDb,EAAMa,EACNC,EAAK,EACN,CACD,CASA,SAASA,EAAMF,EAAQ,CACtB,GAAKA,EACJ,OAAAf,EAAO,2BAA4Be,EAAM,OAAQ,EAC1CT,EAAMS,CAAM,EAIpB,GAFAR,GAAS,EACTP,EAAO,0CAA2CO,EAAOG,CAAI,EACxDC,EAAM,EACV,OAAOE,EAAK,EAEb,GAAKN,IAAUG,EACd,OAAAV,EAAO,mCAAoC,EACpCM,EAAM,KAAMH,CAAI,CAEzB,CACD,CAKAL,EAAO,QAAUG,IC7IjB,IAAAiB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,gCAAiC,EACjDC,EAAW,IACXC,EAAQ,IAoEZ,SAASC,EAASC,EAASC,EAAM,CAChC,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,CAACP,EAAYW,CAAE,EACnB,MAAM,IAAI,UAAWT,EAAQ,mEAAoES,CAAE,CAAE,EAEtG,OAAKF,EAAK,SAAW,QAAUA,EAAK,QAAU,SAC7CA,EAAK,OAAS,IAEVA,EAAK,OACTA,EAAK,MAAQ,EACDA,EAAK,QACjBA,EAAK,MAAQN,GAEPS,EAaP,SAASA,EAAkBC,EAAYC,EAASC,EAAO,CACtD,GAAK,CAACd,EAAcY,CAAW,EAC9B,MAAM,IAAI,UAAWX,EAAQ,sEAAuEW,CAAW,CAAE,EAElH,GAAK,CAACb,EAAYe,CAAK,EACtB,MAAM,IAAI,UAAWb,EAAQ,mEAAoEa,CAAK,CAAE,EAEzG,OAAOV,EAAOQ,EAAYC,EAASL,EAAME,EAAGK,CAAK,EAUjD,SAASA,EAAMC,EAAOC,EAAM,CAC3B,GAAKD,EACJ,OAAOF,EAAME,CAAM,EAEpBF,EAAM,KAAMG,CAAI,CACjB,CACD,CACD,CAKAnB,EAAO,QAAUO,ICnKjB,IAAAa,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,IA8Dd,SAASC,EAAkBC,EAAYC,EAASC,EAASC,EAAKC,EAAO,CACpE,GAAK,UAAU,OAAS,EACvB,OAAON,EAASI,CAAQ,EAAGF,EAAYC,EAASE,CAAI,EAErDL,EAASI,EAASC,CAAI,EAAGH,EAAYC,EAASG,CAAK,CACpD,CAKAP,EAAO,QAAUE,IC9BjB,IAAIM,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "isPositiveInteger", "format", "validate", "opts", "options", "require_limit", "__commonJSMin", "exports", "module", "logger", "debug", "limit", "collection", "acc", "opts", "fcn", "done", "count", "flg", "lim", "len", "idx", "i", "next", "cb", "error", "result", "clbk", "require_factory", "__commonJSMin", "exports", "module", "isFunction", "isCollection", "format", "PINF", "validate", "limit", "factory", "options", "fcn", "opts", "err", "f", "reduceRightAsync", "collection", "initial", "done", "clbk", "error", "acc", "require_main", "__commonJSMin", "exports", "module", "factory", "reduceRightAsync", "collection", "initial", "options", "fcn", "done", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3f22669..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,224 +0,0 @@ - -{{alias}}( collection, initial, [options,] reducer, done ) - Applies a function against an accumulator and each element in a collection - and returns the accumulated result, iterating from right to left. - - When invoked, `reducer` is provided a maximum of five arguments: - - - `accumulator`: accumulated value - - `value`: collection value - - `index`: collection index - - `collection`: the input collection - - `next`: a callback to be invoked after processing a collection `value` - - The actual number of provided arguments depends on function length. If - `reducer` accepts three arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `next` - - If `reducer` accepts four arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `index` - - `next` - - For every other `reducer` signature, `reducer` is provided all five - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `accumulator`: accumulated value - - If a provided function calls the `next` callback with a truthy `error` - argument, the function suspends execution and immediately calls the `done` - callback for subsequent `error` handling. - - Execution is *not* guaranteed to be asynchronous. To guarantee asynchrony, - 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`). - - The function does not support dynamic collection resizing. - - If provided an empty collection, the function invokes the `done` callback - with the `initial` value as the second argument. - - The function does not skip `undefined` elements. - - When processing collection elements concurrently, *beware* of race - conditions when updating an accumulator. This is especially true when an - accumulator is a primitive (e.g., a number). In general, prefer object - accumulators. - - Parameters - ---------- - collection: Array|TypedArray|Object - Input collection over which to iterate. If provided an object, the - object must be array-like (excluding strings and functions). - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - reducer: Function - The function to invoke for each element in a collection. - - done: Function - A callback invoked either upon processing all collection elements or - upon encountering an error. - - Examples - -------- - // Basic usage: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, fcn, done ) - 3000 - 2500 - 1000 - 6500 - - // Limit number of concurrent invocations: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'limit': 2 }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 2500 - 3000 - 1000 - 6500 - - // Process concurrently: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'series': false }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 1000 - 2500 - 3000 - 6500 - - -{{alias}}.factory( [options,] fcn ) - Returns a function which applies a function against an accumulator and each - element in a collection and returns the accumulated result, iterating from - right to left. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - fcn: Function - The function to invoke for each element in a collection. - - Returns - ------- - out: Function - A function which invokes a function for each element in a collection. - - Examples - -------- - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > var opts = { 'series': false }; - > var f = {{alias}}.factory( opts, fcn ); - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > f( arr, acc, done ) - 1000 - 2500 - 3000 - 6500 - > acc = { 'sum': 0 }; - > arr = [ 1000, 1500, 2000 ]; - > f( arr, acc, done ) - 1000 - 1500 - 2000 - 4500 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0455864..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,166 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unsafe-assignment */ - -import reduceRightAsync = require( './index' ); - -const reducer = ( acc: any, value: number, index: number, next: Function ) => { - acc.sum += value; - if ( index === void 0 ) { - throw new Error( '`index` is missing.' ); - } - next( null, acc ); -}; - -const done = ( error: Error | null, acc: any ) => { - if ( error ) { - throw error; - } - if ( acc === void 0 ) { - throw new Error( '`acc` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( 2, acc, reducer, done ); // $ExpectError - reduceRightAsync( false, acc, reducer, done ); // $ExpectError - reduceRightAsync( true, acc, reducer, done ); // $ExpectError - reduceRightAsync( {}, acc, reducer, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a predicate argument which is not a predicate function... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 2, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, false, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, true, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 'abc', done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, [], done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a done callback argument which is not a function having a supported signature... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 2 ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, false ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, true ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 'abc' ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, {} ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, [] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const acc = { 'sum': 0 }; - reduceRightAsync(); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, reducer, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - reduceRightAsync.factory( reducer ); // $ExpectType FactoryFunction - reduceRightAsync.factory( { 'series': true }, reducer ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - reduceRightAsync.factory( [], reducer ); // $ExpectError - reduceRightAsync.factory( 123, reducer ); // $ExpectError - reduceRightAsync.factory( 'abc', reducer ); // $ExpectError - reduceRightAsync.factory( false, reducer ); // $ExpectError - reduceRightAsync.factory( true, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not a predicate function... -{ - reduceRightAsync.factory( {} ); // $ExpectError - reduceRightAsync.factory( true ); // $ExpectError - reduceRightAsync.factory( false ); // $ExpectError - reduceRightAsync.factory( {}, 123 ); // $ExpectError - reduceRightAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1( 12, acc, done ); // $ExpectError - fcn1( true, acc, done ); // $ExpectError - fcn1( false, acc, done ); // $ExpectError - fcn1( {}, acc, done ); // $ExpectError - - fcn1( [ 3000, 2500, 1000 ], acc, 12 ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, true ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, false ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, '5' ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, {} ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, [] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1(); // $ExpectError - fcn1( [ 3000, 2500, 1000 ] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - reduceRightAsync.factory( { 'limit': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': true }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': false }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - reduceRightAsync.factory( { 'series': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': 12 }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - reduceRightAsync.factory(); // $ExpectError - reduceRightAsync.factory( {}, reducer, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index dd64345..0000000 --- a/examples/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var resolve = require( 'path' ).resolve; -var readFile = require( '@stdlib/fs-read-file' ); -var reduceRightAsync = require( './../lib' ); - -var files = [ - resolve( __dirname, '..', 'package.json' ), - resolve( __dirname, '..', 'README.md' ) -]; - -function done( error, acc ) { - if ( error ) { - throw error; - } - console.log( acc.count ); -} - -function read( acc, file, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( file, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( null, acc ); - } - acc.count += 1; - next( null, acc ); - } -} - -var acc = { - 'count': 0 -}; -reduceRightAsync( files, acc, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 28e0a36..f6cba5d 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..ab01fae --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import{isPrimitive as c}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.1-esm/index.mjs";function m(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var d=m(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function f(e,m){var f,u,p;if(f={},arguments.length>1){if(u=function(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("1RZ2o","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!c(e.limit))?new TypeError(r("1RZ3P","limit",e.limit)):null):new TypeError(r("1RZ2V",t))}(f,e),u)throw u;p=m}else p=e;if(!t(p))throw new TypeError(r("1RZ3q",p));return void 0===f.series&&void 0===f.limit&&(f.series=!0),f.series?f.limit=1:f.limit||(f.limit=s),function(e,s,n){if(!i(e))throw new TypeError(r("1RZAh",e));if(!t(n))throw new TypeError(r("1RZ3q",n));return function(e,t,i,r,s){var n,o,l,c,m,f;if(c=e.length,d("Collection length: %d",c),0===c)return d("Finished processing a collection."),s(null,t);for(l=c0&&u();function u(){function s(e,i){if(!o){if(e)return o=!0,p(e);d("Accumulator: %s",JSON.stringify(i)),t=i,p()}}d("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function p(e){return e?(d("Encountered an error: %s",e.message),s(e)):(d("Processed %d of %d collection elements.",n+=1,c),m>0?u():n===c?(d("Finished processing a collection."),s(null,t)):void 0)}}(e,s,f,p,(function(e,t){if(e)return n(e);n(null,t)}))}}function u(e,t,i,r,s){if(arguments.length<5)return f(i)(e,t,r);f(i,r)(e,t,s)}e(u,"factory",f);export{u as default,f as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..e11f2cb --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/limit.js","../lib/factory.js","../lib/validate.js","../lib/main.js","../lib/index.js"],"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 logger = require( 'debug' );\n\n\n// VARIABLES //\n\nvar debug = logger( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RZ3q', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '1RZAh', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RZ3q', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '1RZ2V', 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( '1RZ2o', '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( '1RZ3P', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["debug","logger","factory","options","fcn","opts","err","f","arguments","length","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","validate","isFunction","PINF","collection","initial","done","isCollection","acc","count","flg","lim","len","idx","i","next","cb","error","result","clbk","JSON","stringify","call","message","reduceRightAsync","setReadOnly","main"],"mappings":";;81CA2BIA,uDAAQC,CAAQ,4BCoEpB,SAASC,EAASC,EAASC,GAC1B,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAA,EACFG,UAAUC,OAAS,EAAI,CAE3B,GADAH,EChDF,SAAmBD,EAAMF,GACxB,OAAMO,EAAUP,IAGXQ,EAAYR,EAAS,aACzBE,EAAKO,QAAUT,EAAQS,SAEnBD,EAAYR,EAAS,YACzBE,EAAKQ,OAASV,EAAQU,QAChBC,EAAWT,EAAKQ,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUX,EAAKQ,SAGnDF,EAAYR,EAAS,WACzBE,EAAKY,MAAQd,EAAQc,OACfC,EAAmBb,EAAKY,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASX,EAAKY,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASb,GAkBzC,CD4BQgB,CAAUd,EAAMF,GACjBG,EACJ,MAAMA,EAEPC,EAAIH,CACN,MACEG,EAAIJ,EAEL,IAAMiB,EAAYb,GACjB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAUvC,YARqB,IAAhBF,EAAKQ,aAAoC,IAAfR,EAAKY,QACnCZ,EAAKQ,QAAS,GAEVR,EAAKQ,OACTR,EAAKY,MAAQ,EACDZ,EAAKY,QACjBZ,EAAKY,MAAQI,GAed,SAA2BC,EAAYC,EAASC,GAC/C,IAAMC,EAAcH,GACnB,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,IAAMF,EAAYI,GACjB,MAAM,IAAIT,UAAWC,EAAQ,QAASQ,IAEvC,ODhGF,SAAgBF,EAAYI,EAAKrB,EAAMD,EAAKoB,GAC3C,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMR,EAAWb,OACjBT,EAAO,wBAAyB8B,GAEnB,IAARA,EAEJ,OADA9B,EAAO,qCACAwB,EAAM,KAAME,GAYpB,IATCG,EADIC,EAAMzB,EAAKY,MACTa,EAEAzB,EAAKY,MAEZjB,EAAO,wBAAyB6B,GAChC7B,EAAO,0BAA2BI,EAAIK,QAEtCkB,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVE,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKR,EAAL,CAIA,GAAKO,EAEJ,OADAP,GAAM,EACCS,EAAMF,GAEdnC,EAAO,kBAAmBsC,KAAKC,UAAWH,IAC1CV,EAAMU,EACNC,GAPC,CAQD,CA5BDrC,EAAO,6BADP+B,GAAO,EACmCO,KAAKC,UAAWjB,EAAYS,KAClD,IAAf3B,EAAIK,OACRL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOG,GACtB,IAAf9B,EAAIK,OACfL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKG,GAErD9B,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKT,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJnC,EAAO,2BAA4BmC,EAAMM,SAClCjB,EAAMW,KAGdnC,EAAO,0CADP2B,GAAS,EACgDG,GACpDC,EAAM,EACHE,IAEHN,IAAUG,GACd9B,EAAO,qCACAwB,EAAM,KAAME,SAFpB,EAIA,CACF,CCKST,CAAOK,EAAYC,EAASlB,EAAME,GAUzC,SAAe4B,EAAOT,GACrB,GAAKS,EACJ,OAAOX,EAAMW,GAEdX,EAAM,KAAME,EACZ,GACD,CACF,CE1EA,SAASgB,EAAkBpB,EAAYC,EAASpB,EAASC,EAAKoB,GAC7D,GAAKhB,UAAUC,OAAS,EACvB,OAAOP,EAASC,EAATD,CAAoBoB,EAAYC,EAASnB,GAEjDF,EAASC,EAASC,EAAlBF,CAAyBoB,EAAYC,EAASC,EAC/C,CClBAmB,EAAAC,EAAA,UAAA1C"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index e107128..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,164 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var validate = require( './validate.js' ); -var limit = require( './limit.js' ); - - -// MAIN // - -/** -* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} last argument must be a function -* @returns {Function} function which invokes the provided function once for each element in a collection -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error, data ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var opts = { -* 'series': false -* }; -* -* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: -* var reduceRightAsync = factory( opts, read ); -* -* // Create a collection over which to iterate: -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* // Define a callback which handles errors: -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* // Run `read` for each element in `files`: -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, done ); -*/ -function factory( options, fcn ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = fcn; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '1RZ3q', f ) ); - } - if ( opts.series === void 0 && opts.limit === void 0 ) { - opts.series = true; - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return reduceRightAsync; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * @private - * @param {Collection} collection - input collection - * @param {*} initial - initial value - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be a collection - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function reduceRightAsync( collection, initial, done ) { - if ( !isCollection( collection ) ) { - throw new TypeError( format( '1RZAh', collection ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '1RZ3q', done ) ); - } - return limit( collection, initial, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {*} [acc] - accumulated value - * @returns {void} - */ - function clbk( error, acc ) { - if ( error ) { - return done( error ); - } - done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ae657ff..0000000 --- a/lib/index.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* @module @stdlib/utils-async-reduce-right -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' ); -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/limit.js b/lib/limit.js deleted file mode 100644 index cdb60af..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); - - -// VARIABLES // - -var debug = logger( 'reduce-right-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each element in a collection, limiting the number of concurrently pending functions and iterating from right to left. -* -* @private -* @param {Collection} collection - input collection -* @param {*} acc - initial value -* @param {Options} opts - function options -* @param {*} [opts.thisArg] - execution context -* @param {PositiveInteger} [opts.limit] - maximum number of pending function invocations -* @param {Function} fcn - function to invoke -* @param {Callback} done - function to invoke upon completion or upon encountering an error -* @returns {void} -*/ -function limit( collection, acc, opts, fcn, done ) { - var count; - var flg; - var lim; - var len; - var idx; - var i; - - len = collection.length; - debug( 'Collection length: %d', len ); - - if ( len === 0 ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - count = 0; - idx = len; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all collection elements... - if ( idx > 0 ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next element in a collection. - * - * @private - */ - function next() { - idx -= 1; - debug( 'Collection element %d: %s.', idx, JSON.stringify( collection[ idx ] ) ); - if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], cb ); - } else if ( fcn.length === 4 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, cb ); - } else { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len - } - /** - * Callback invoked once a provided function finishes processing a collection element. - * - * @private - * @param {*} [error] - error - * @param {*} [result] - accumulation result - * @returns {void} - */ - function cb( error, result ) { - if ( flg ) { - // Prevent further processing of collection elements: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Accumulator: %s', JSON.stringify( result ) ); - acc = result; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next collection element. - * - * @private - * @param {*} [error] - error - * @returns {void} - */ - function clbk( error ) { - if ( error ) { - debug( 'Encountered an error: %s', error.message ); - return done( error ); - } - count += 1; - debug( 'Processed %d of %d collection elements.', count, len ); - if ( idx > 0 ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index c8b0d0f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param {Collection} collection - input collection -* @param {*} initial - initial value -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} second-to-last argument must be a function -* @throws {TypeError} last argument must be a function -* @returns {void} -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -function reduceRightAsync( collection, initial, options, fcn, done ) { - if ( arguments.length < 5 ) { - return factory( options )( collection, initial, fcn ); - } - factory( options, fcn )( collection, initial, done ); -} - - -// EXPORTS // - -module.exports = reduceRightAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 0c666fe..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @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 -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'thisArg': {}, -* 'series': false, -* 'limit': 10 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '1RZ2V', options ) ); - } - if ( hasOwnProp( options, 'thisArg' ) ) { - opts.thisArg = options.thisArg; - } - if ( hasOwnProp( options, 'series' ) ) { - opts.series = options.series; - if ( !isBoolean( opts.series ) ) { - return new TypeError( format( '1RZ2o', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '1RZ3P', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index eaf0e2f..3464c63 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,44 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-boolean": "^0.2.1", - "@stdlib/assert-is-collection": "^0.2.1", - "@stdlib/assert-is-function": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/assert-is-positive-integer": "^0.2.1", - "@stdlib/constants-float64-pinf": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", - "debug": "^2.6.9", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/constants-float64-eps": "^0.2.1", - "@stdlib/fs-read-file": "^0.2.1", - "@stdlib/utils-noop": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..9a829df --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 8244931..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1095 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( {}, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, next ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - factory( opts, next ); - }; - } -}); - -tape( 'the function returns a function (no options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided a collection (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a collection (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (1 argument)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (2 arguments)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with five arguments', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn() { - var value; - var next; - var acc; - var k; - - acc = arguments[ 0 ]; - value = arguments[ 1 ]; - k = arguments[ 2 ]; - next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( k, i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the returned function supports processing collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements concurrently', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 100, 250, 300 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements sequentially (limit = 1)', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of collection elements which are processed at any one time', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 250, 300, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 250, 100, 300 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var reduceRightAsync; - var arr; - - reduceRightAsync = factory( fcn ); - arr = []; - - reduceRightAsync( arr, 0, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var reduceRightAsync; - var obj; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = []; - obj = {}; - reduceRightAsync( arr, obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - i = 0; - - reduceRightAsync( arr, {}, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, acc ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the returned function does not skip empty elements', function test( t ) { - var reduceRightAsync; - var expected; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index f273a40..0000000 --- a/test/test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof reduceRightAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 1893240..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1035 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a collection', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (no options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, next, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, 0 ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - reduceRightAsync( [ 1, 2, 3 ], 0, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (1 argument)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (2 arguments)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with five arguments', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn() { - var next; - var acc; - var v; - - next = arguments[ 4 ]; - acc = arguments[ 0 ]; - v = arguments[ 1 ]; - - i -= 1; - j += 1; - - t.strictEqual( v, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, v ); - - function onTimeout() { - acc.sum += v; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'by default, the function processes collection elements sequentially', function test( t ) { - var values; - var count; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements concurrently', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 100, 250, 300 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': true - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially (limit = 1)', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var arr; - var ctx; - - arr = [ 3, 2, 1 ]; - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 3, 2, 1 ]; - opts = { - 'series': true - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 250, 100, 300 ]; - opts = { - 'limit': 2 - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var arr = []; - reduceRightAsync( arr, 0, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var arr = []; - var obj = {}; - - reduceRightAsync( arr, obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - arr = [ 3, 2, 1 ]; - i = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, value ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the function does not skip empty elements', function test( t ) { - var expected; - var arr; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, fcn, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 7660838..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,181 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `limit` option which is not a positive integer', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - -5, - 0, - 3.14, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'limit': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `series` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'series': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function accepts any value for the `thisArg` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'thisArg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err, null, 'returns null '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'thisArg': {}, - 'series': false, - 'limit': 10 - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From 70c528d52260d5115b7d76e8ecffbaacaeb9494c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 00:01:18 +0000 Subject: [PATCH 110/147] Transform error messages --- lib/factory.js | 8 ++++---- lib/validate.js | 8 ++++---- package.json | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 1125052..e107128 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -22,7 +22,7 @@ var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var PINF = require( '@stdlib/constants-float64-pinf' ); var validate = require( './validate.js' ); var limit = require( './limit.js' ); @@ -109,7 +109,7 @@ function factory( options, fcn ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '1RZ3q', f ) ); } if ( opts.series === void 0 && opts.limit === void 0 ) { opts.series = true; @@ -134,10 +134,10 @@ function factory( options, fcn ) { */ function reduceRightAsync( collection, initial, done ) { if ( !isCollection( collection ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a collection. Value: `%s`.', collection ) ); + throw new TypeError( format( '1RZAh', collection ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '1RZ3q', done ) ); } return limit( collection, initial, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index 9ba927e..0c666fe 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,7 +54,7 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '1RZ2V', options ) ); } if ( hasOwnProp( options, 'thisArg' ) ) { opts.thisArg = options.thisArg; @@ -62,13 +62,13 @@ function validate( opts, options ) { if ( hasOwnProp( options, 'series' ) ) { opts.series = options.series; if ( !isBoolean( opts.series ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'series', opts.series ) ); + return new TypeError( format( '1RZ2o', 'series', opts.series ) ); } } if ( hasOwnProp( options, 'limit' ) ) { opts.limit = options.limit; if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'limit', opts.limit ) ); + return new TypeError( format( '1RZ3P', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index 31e9a96..eaf0e2f 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-plain-object": "^0.2.1", "@stdlib/assert-is-positive-integer": "^0.2.1", "@stdlib/constants-float64-pinf": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", "debug": "^2.6.9", From 038cf2d4da74537118fc89e7eccf71fed03f1272 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 05:00:16 +0000 Subject: [PATCH 111/147] Remove files --- index.d.ts | 410 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5257 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index f6cba5d..0000000 --- a/index.d.ts +++ /dev/null @@ -1,410 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Execution context. - */ - thisArg?: ThisParameterType>; - - /** - * The maximum number of pending invocations at any one time. - */ - limit?: number; - - /** - * Boolean indicating whether to sequentially invoke the reducer function for each `collection` element. If `true`, the function sets `options.limit=1`. Default: true. - */ - series?: boolean; -} - -/** -* Callback function. -*/ -type Nullary = () => void; - -/** -* Callback function. -* -* @param error - encountered error or null -*/ -type Unary = ( error: Error | null ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Binary = ( error: Error | null, accumulator: U ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param next - a callback to be invoked after processing a collection `value` -*/ -type TernaryReducer = ( this: V, accumulator: U, value: T, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuaternaryReducer = ( this: V, accumulator: U, value: T, index: number, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuinaryReducer = ( this: V, accumulator: U, value: T, index: number, collection: Collection, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type Reducer = TernaryReducer | QuaternaryReducer | QuinaryReducer; - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result. -* -* @param collection - input collection -* @param initial - initial value -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( collection: Collection, initial: U, done: Callback ) => void; - -/** -* Interface for `reduceRightAsync`. -*/ -interface ReduceRightAsync { - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, {}, read, done ); - */ - ( collection: Collection, initial: U, options: Options, reducer: Reducer, done: Callback ): void; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, read, done ); - */ - ( collection: Collection, initial: U, reducer: Reducer, done: Callback ): void; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @throws must provide valid options - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var opts = { - * 'series': false - * }; - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( opts, read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( options: Options, reducer: Reducer ): FactoryFunction; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param reducer - function to invoke for each element in a collection - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( reducer: Reducer ): FactoryFunction; -} - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param collection - input collection -* @param initial - initial value -* @param options - function options -* @param options.thisArg - execution context -* @param options.limit - maximum number of pending invocations at any one time -* @param 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 (default: true) -* @param reducer - function to invoke for each element in a collection -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -declare var reduceRightAsync: ReduceRightAsync; - - -// EXPORTS // - -export = reduceRightAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index ab01fae..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import{isPrimitive as c}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.1-esm/index.mjs";function m(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var d=m(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function f(e,m){var f,u,p;if(f={},arguments.length>1){if(u=function(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("1RZ2o","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!c(e.limit))?new TypeError(r("1RZ3P","limit",e.limit)):null):new TypeError(r("1RZ2V",t))}(f,e),u)throw u;p=m}else p=e;if(!t(p))throw new TypeError(r("1RZ3q",p));return void 0===f.series&&void 0===f.limit&&(f.series=!0),f.series?f.limit=1:f.limit||(f.limit=s),function(e,s,n){if(!i(e))throw new TypeError(r("1RZAh",e));if(!t(n))throw new TypeError(r("1RZ3q",n));return function(e,t,i,r,s){var n,o,l,c,m,f;if(c=e.length,d("Collection length: %d",c),0===c)return d("Finished processing a collection."),s(null,t);for(l=c0&&u();function u(){function s(e,i){if(!o){if(e)return o=!0,p(e);d("Accumulator: %s",JSON.stringify(i)),t=i,p()}}d("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function p(e){return e?(d("Encountered an error: %s",e.message),s(e)):(d("Processed %d of %d collection elements.",n+=1,c),m>0?u():n===c?(d("Finished processing a collection."),s(null,t)):void 0)}}(e,s,f,p,(function(e,t){if(e)return n(e);n(null,t)}))}}function u(e,t,i,r,s){if(arguments.length<5)return f(i)(e,t,r);f(i,r)(e,t,s)}e(u,"factory",f);export{u as default,f as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index e11f2cb..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/limit.js","../lib/factory.js","../lib/validate.js","../lib/main.js","../lib/index.js"],"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 logger = require( 'debug' );\n\n\n// VARIABLES //\n\nvar debug = logger( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RZ3q', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '1RZAh', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RZ3q', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '1RZ2V', 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( '1RZ2o', '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( '1RZ3P', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["debug","logger","factory","options","fcn","opts","err","f","arguments","length","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","validate","isFunction","PINF","collection","initial","done","isCollection","acc","count","flg","lim","len","idx","i","next","cb","error","result","clbk","JSON","stringify","call","message","reduceRightAsync","setReadOnly","main"],"mappings":";;81CA2BIA,uDAAQC,CAAQ,4BCoEpB,SAASC,EAASC,EAASC,GAC1B,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAA,EACFG,UAAUC,OAAS,EAAI,CAE3B,GADAH,EChDF,SAAmBD,EAAMF,GACxB,OAAMO,EAAUP,IAGXQ,EAAYR,EAAS,aACzBE,EAAKO,QAAUT,EAAQS,SAEnBD,EAAYR,EAAS,YACzBE,EAAKQ,OAASV,EAAQU,QAChBC,EAAWT,EAAKQ,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUX,EAAKQ,SAGnDF,EAAYR,EAAS,WACzBE,EAAKY,MAAQd,EAAQc,OACfC,EAAmBb,EAAKY,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASX,EAAKY,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASb,GAkBzC,CD4BQgB,CAAUd,EAAMF,GACjBG,EACJ,MAAMA,EAEPC,EAAIH,CACN,MACEG,EAAIJ,EAEL,IAAMiB,EAAYb,GACjB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAUvC,YARqB,IAAhBF,EAAKQ,aAAoC,IAAfR,EAAKY,QACnCZ,EAAKQ,QAAS,GAEVR,EAAKQ,OACTR,EAAKY,MAAQ,EACDZ,EAAKY,QACjBZ,EAAKY,MAAQI,GAed,SAA2BC,EAAYC,EAASC,GAC/C,IAAMC,EAAcH,GACnB,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,IAAMF,EAAYI,GACjB,MAAM,IAAIT,UAAWC,EAAQ,QAASQ,IAEvC,ODhGF,SAAgBF,EAAYI,EAAKrB,EAAMD,EAAKoB,GAC3C,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMR,EAAWb,OACjBT,EAAO,wBAAyB8B,GAEnB,IAARA,EAEJ,OADA9B,EAAO,qCACAwB,EAAM,KAAME,GAYpB,IATCG,EADIC,EAAMzB,EAAKY,MACTa,EAEAzB,EAAKY,MAEZjB,EAAO,wBAAyB6B,GAChC7B,EAAO,0BAA2BI,EAAIK,QAEtCkB,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVE,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKR,EAAL,CAIA,GAAKO,EAEJ,OADAP,GAAM,EACCS,EAAMF,GAEdnC,EAAO,kBAAmBsC,KAAKC,UAAWH,IAC1CV,EAAMU,EACNC,GAPC,CAQD,CA5BDrC,EAAO,6BADP+B,GAAO,EACmCO,KAAKC,UAAWjB,EAAYS,KAClD,IAAf3B,EAAIK,OACRL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOG,GACtB,IAAf9B,EAAIK,OACfL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKG,GAErD9B,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKT,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJnC,EAAO,2BAA4BmC,EAAMM,SAClCjB,EAAMW,KAGdnC,EAAO,0CADP2B,GAAS,EACgDG,GACpDC,EAAM,EACHE,IAEHN,IAAUG,GACd9B,EAAO,qCACAwB,EAAM,KAAME,SAFpB,EAIA,CACF,CCKST,CAAOK,EAAYC,EAASlB,EAAME,GAUzC,SAAe4B,EAAOT,GACrB,GAAKS,EACJ,OAAOX,EAAMW,GAEdX,EAAM,KAAME,EACZ,GACD,CACF,CE1EA,SAASgB,EAAkBpB,EAAYC,EAASpB,EAASC,EAAKoB,GAC7D,GAAKhB,UAAUC,OAAS,EACvB,OAAOP,EAASC,EAATD,CAAoBoB,EAAYC,EAASnB,GAEjDF,EAASC,EAASC,EAAlBF,CAAyBoB,EAAYC,EAASC,EAC/C,CClBAmB,EAAAC,EAAA,UAAA1C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 9a829df..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 051786bfaa4136dc3042c3009a1b49fc2c73ca4a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 05:00:31 +0000 Subject: [PATCH 112/147] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 ---- .github/workflows/publish.yml | 249 -- .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 134 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.factory.js | 73 - benchmark/benchmark.js | 160 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 224 - docs/types/test.ts | 166 - examples/index.js | 55 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 164 - lib/index.js | 77 - lib/limit.js | 142 - lib/main.js | 95 - lib/validate.js | 80 - package.json | 65 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 1095 ----- test/test.js | 38 - test/test.main.js | 1035 ----- test/test.validate.js | 181 - 49 files changed, 4873 insertions(+), 6957 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/limit.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1e08946..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 5358060..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index fa37f2d..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '37 1 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index ec90164..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -460,7 +457,7 @@ reduceRightAsync( files, acc, read, done ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -531,11 +528,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right +[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right/tree/esm -[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce +[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index b155fd2..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var reduceRightAsync; - var arr; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - reduceRightAsync = factory( onItem ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - var acc; - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index af5c346..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var reduceRightAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=false', function benchmark( b ) { - var opts; - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'series': false - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var arr; - var len; - var acc; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'limit': 3 - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b8adcd2..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right" -%% click B href "https://github.com/stdlib-js/utils-async-reduce-right/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-reduce-right/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-reduce-right/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-reduce-right/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right -[production-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-async-reduce-right/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-async-reduce-right/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-async-reduce-right/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 47a072e..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import reduceRightAsync from '../docs/types/index'; -export = reduceRightAsync; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 530ca4d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var c=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var x=c(function(U,O){ -var R=require('@stdlib/assert-is-plain-object/dist'),h=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,k=require('@stdlib/assert-is-positive-integer/dist').isPrimitive,d=require('@stdlib/error-tools-fmtprodmsg/dist');function I(e,r){return R(r)?(h(r,"thisArg")&&(e.thisArg=r.thisArg),h(r,"series")&&(e.series=r.series,!j(e.series))?new TypeError(d('1RZ2o',"series",e.series)):h(r,"limit")&&(e.limit=r.limit,!k(e.limit))?new TypeError(d('1RZ3P',"limit",e.limit)):null):new TypeError(d('1RZ2V',r));}O.exports=I -});var P=c(function(W,E){ -var J=require("debug"),a=J("reduce-right-async:limit");function L(e,r,i,t,s){var f,m,v,n,u,g;if(n=e.length,a("Collection length: %d",n),n===0)return a("Finished processing a collection."),s(null,r);for(n0&&o();function o(){u-=1,a("Collection element %d: %s.",u,JSON.stringify(e[u])),t.length===3?t.call(i.thisArg,r,e[u],l):t.length===4?t.call(i.thisArg,r,e[u],u,l):t.call(i.thisArg,r,e[u],u,e,l);function l(w,A){if(!m){if(w)return m=!0,b(w);a("Accumulator: %s",JSON.stringify(A)),r=A,b()}}}function b(l){if(l)return a("Encountered an error: %s",l.message),s(l);if(f+=1,a("Processed %d of %d collection elements.",f,n),u>0)return o();if(f===n)return a("Finished processing a collection."),s(null,r)}}E.exports=L -});var q=c(function(X,F){ -var T=require('@stdlib/assert-is-function/dist'),S=require('@stdlib/assert-is-collection/dist'),y=require('@stdlib/error-tools-fmtprodmsg/dist'),B=require('@stdlib/constants-float64-pinf/dist'),z=x(),D=P();function G(e,r){var i,t,s;if(i={},arguments.length>1){if(t=z(i,e),t)throw t;s=r}else s=e;if(!T(s))throw new TypeError(y('1RZ3q',s));return i.series===void 0&&i.limit===void 0&&(i.series=!0),i.series?i.limit=1:i.limit||(i.limit=B),f;function f(m,v,n){if(!S(m))throw new TypeError(y('1RZAh',m));if(!T(n))throw new TypeError(y('1RZ3q',n));return D(m,v,i,s,u);function u(g,o){if(g)return n(g);n(null,o)}}}F.exports=G -});var N=c(function(Y,C){ -var p=q();function H(e,r,i,t,s){if(arguments.length<5)return p(i)(e,r,t);p(i,t)(e,r,s)}C.exports=H -});var K=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),V=N(),M=q();K(V,"factory",M);module.exports=V; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index acb9d67..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/limit.js", "../lib/factory.js", "../lib/main.js", "../lib/index.js"], - "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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\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 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 to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\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 === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, 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 ( !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, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\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* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nmodule.exports = reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' );\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, 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"], - "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,0BAA2B,EAkB/C,SAASE,EAAOC,EAAYC,EAAKC,EAAMC,EAAKC,EAAO,CAClD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMR,EAAW,OACjBF,EAAO,wBAAyBU,CAAI,EAE/BA,IAAQ,EACZ,OAAAV,EAAO,mCAAoC,EACpCM,EAAM,KAAMH,CAAI,EAYxB,IAVKO,EAAMN,EAAK,MACfK,EAAMC,EAEND,EAAML,EAAK,MAEZJ,EAAO,wBAAyBS,CAAI,EACpCT,EAAO,0BAA2BK,EAAI,MAAO,EAE7CE,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVE,EAAK,EAQP,SAASA,GAAO,CACfF,GAAO,EACPX,EAAO,6BAA8BW,EAAK,KAAK,UAAWT,EAAYS,CAAI,CAAE,CAAE,EACzEN,EAAI,SAAW,EACnBA,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGG,CAAG,EACxCT,EAAI,SAAW,EAC1BA,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGA,EAAKG,CAAG,EAExDT,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGA,EAAKT,EAAYY,CAAG,EAUrE,SAASA,EAAIC,EAAOC,EAAS,CAC5B,GAAK,CAAAR,EAIL,IAAKO,EACJ,OAAAP,EAAM,GACCS,EAAMF,CAAM,EAEpBf,EAAO,kBAAmB,KAAK,UAAWgB,CAAO,CAAE,EACnDb,EAAMa,EACNC,EAAK,EACN,CACD,CASA,SAASA,EAAMF,EAAQ,CACtB,GAAKA,EACJ,OAAAf,EAAO,2BAA4Be,EAAM,OAAQ,EAC1CT,EAAMS,CAAM,EAIpB,GAFAR,GAAS,EACTP,EAAO,0CAA2CO,EAAOG,CAAI,EACxDC,EAAM,EACV,OAAOE,EAAK,EAEb,GAAKN,IAAUG,EACd,OAAAV,EAAO,mCAAoC,EACpCM,EAAM,KAAMH,CAAI,CAEzB,CACD,CAKAL,EAAO,QAAUG,IC7IjB,IAAAiB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,gCAAiC,EACjDC,EAAW,IACXC,EAAQ,IAoEZ,SAASC,EAASC,EAASC,EAAM,CAChC,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,CAACP,EAAYW,CAAE,EACnB,MAAM,IAAI,UAAWT,EAAQ,mEAAoES,CAAE,CAAE,EAEtG,OAAKF,EAAK,SAAW,QAAUA,EAAK,QAAU,SAC7CA,EAAK,OAAS,IAEVA,EAAK,OACTA,EAAK,MAAQ,EACDA,EAAK,QACjBA,EAAK,MAAQN,GAEPS,EAaP,SAASA,EAAkBC,EAAYC,EAASC,EAAO,CACtD,GAAK,CAACd,EAAcY,CAAW,EAC9B,MAAM,IAAI,UAAWX,EAAQ,sEAAuEW,CAAW,CAAE,EAElH,GAAK,CAACb,EAAYe,CAAK,EACtB,MAAM,IAAI,UAAWb,EAAQ,mEAAoEa,CAAK,CAAE,EAEzG,OAAOV,EAAOQ,EAAYC,EAASL,EAAME,EAAGK,CAAK,EAUjD,SAASA,EAAMC,EAAOC,EAAM,CAC3B,GAAKD,EACJ,OAAOF,EAAME,CAAM,EAEpBF,EAAM,KAAMG,CAAI,CACjB,CACD,CACD,CAKAnB,EAAO,QAAUO,ICnKjB,IAAAa,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,IA8Dd,SAASC,EAAkBC,EAAYC,EAASC,EAASC,EAAKC,EAAO,CACpE,GAAK,UAAU,OAAS,EACvB,OAAON,EAASI,CAAQ,EAAGF,EAAYC,EAASE,CAAI,EAErDL,EAASI,EAASC,CAAI,EAAGH,EAAYC,EAASG,CAAK,CACpD,CAKAP,EAAO,QAAUE,IC9BjB,IAAIM,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "isPositiveInteger", "format", "validate", "opts", "options", "require_limit", "__commonJSMin", "exports", "module", "logger", "debug", "limit", "collection", "acc", "opts", "fcn", "done", "count", "flg", "lim", "len", "idx", "i", "next", "cb", "error", "result", "clbk", "require_factory", "__commonJSMin", "exports", "module", "isFunction", "isCollection", "format", "PINF", "validate", "limit", "factory", "options", "fcn", "opts", "err", "f", "reduceRightAsync", "collection", "initial", "done", "clbk", "error", "acc", "require_main", "__commonJSMin", "exports", "module", "factory", "reduceRightAsync", "collection", "initial", "options", "fcn", "done", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3f22669..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,224 +0,0 @@ - -{{alias}}( collection, initial, [options,] reducer, done ) - Applies a function against an accumulator and each element in a collection - and returns the accumulated result, iterating from right to left. - - When invoked, `reducer` is provided a maximum of five arguments: - - - `accumulator`: accumulated value - - `value`: collection value - - `index`: collection index - - `collection`: the input collection - - `next`: a callback to be invoked after processing a collection `value` - - The actual number of provided arguments depends on function length. If - `reducer` accepts three arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `next` - - If `reducer` accepts four arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `index` - - `next` - - For every other `reducer` signature, `reducer` is provided all five - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `accumulator`: accumulated value - - If a provided function calls the `next` callback with a truthy `error` - argument, the function suspends execution and immediately calls the `done` - callback for subsequent `error` handling. - - Execution is *not* guaranteed to be asynchronous. To guarantee asynchrony, - 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`). - - The function does not support dynamic collection resizing. - - If provided an empty collection, the function invokes the `done` callback - with the `initial` value as the second argument. - - The function does not skip `undefined` elements. - - When processing collection elements concurrently, *beware* of race - conditions when updating an accumulator. This is especially true when an - accumulator is a primitive (e.g., a number). In general, prefer object - accumulators. - - Parameters - ---------- - collection: Array|TypedArray|Object - Input collection over which to iterate. If provided an object, the - object must be array-like (excluding strings and functions). - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - reducer: Function - The function to invoke for each element in a collection. - - done: Function - A callback invoked either upon processing all collection elements or - upon encountering an error. - - Examples - -------- - // Basic usage: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, fcn, done ) - 3000 - 2500 - 1000 - 6500 - - // Limit number of concurrent invocations: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'limit': 2 }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 2500 - 3000 - 1000 - 6500 - - // Process concurrently: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'series': false }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 1000 - 2500 - 3000 - 6500 - - -{{alias}}.factory( [options,] fcn ) - Returns a function which applies a function against an accumulator and each - element in a collection and returns the accumulated result, iterating from - right to left. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - fcn: Function - The function to invoke for each element in a collection. - - Returns - ------- - out: Function - A function which invokes a function for each element in a collection. - - Examples - -------- - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > var opts = { 'series': false }; - > var f = {{alias}}.factory( opts, fcn ); - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > f( arr, acc, done ) - 1000 - 2500 - 3000 - 6500 - > acc = { 'sum': 0 }; - > arr = [ 1000, 1500, 2000 ]; - > f( arr, acc, done ) - 1000 - 1500 - 2000 - 4500 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0455864..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,166 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unsafe-assignment */ - -import reduceRightAsync = require( './index' ); - -const reducer = ( acc: any, value: number, index: number, next: Function ) => { - acc.sum += value; - if ( index === void 0 ) { - throw new Error( '`index` is missing.' ); - } - next( null, acc ); -}; - -const done = ( error: Error | null, acc: any ) => { - if ( error ) { - throw error; - } - if ( acc === void 0 ) { - throw new Error( '`acc` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( 2, acc, reducer, done ); // $ExpectError - reduceRightAsync( false, acc, reducer, done ); // $ExpectError - reduceRightAsync( true, acc, reducer, done ); // $ExpectError - reduceRightAsync( {}, acc, reducer, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a predicate argument which is not a predicate function... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 2, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, false, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, true, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 'abc', done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, [], done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a done callback argument which is not a function having a supported signature... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 2 ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, false ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, true ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 'abc' ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, {} ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, [] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const acc = { 'sum': 0 }; - reduceRightAsync(); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, reducer, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - reduceRightAsync.factory( reducer ); // $ExpectType FactoryFunction - reduceRightAsync.factory( { 'series': true }, reducer ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - reduceRightAsync.factory( [], reducer ); // $ExpectError - reduceRightAsync.factory( 123, reducer ); // $ExpectError - reduceRightAsync.factory( 'abc', reducer ); // $ExpectError - reduceRightAsync.factory( false, reducer ); // $ExpectError - reduceRightAsync.factory( true, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not a predicate function... -{ - reduceRightAsync.factory( {} ); // $ExpectError - reduceRightAsync.factory( true ); // $ExpectError - reduceRightAsync.factory( false ); // $ExpectError - reduceRightAsync.factory( {}, 123 ); // $ExpectError - reduceRightAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1( 12, acc, done ); // $ExpectError - fcn1( true, acc, done ); // $ExpectError - fcn1( false, acc, done ); // $ExpectError - fcn1( {}, acc, done ); // $ExpectError - - fcn1( [ 3000, 2500, 1000 ], acc, 12 ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, true ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, false ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, '5' ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, {} ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, [] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1(); // $ExpectError - fcn1( [ 3000, 2500, 1000 ] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - reduceRightAsync.factory( { 'limit': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': true }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': false }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - reduceRightAsync.factory( { 'series': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': 12 }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - reduceRightAsync.factory(); // $ExpectError - reduceRightAsync.factory( {}, reducer, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index dd64345..0000000 --- a/examples/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var resolve = require( 'path' ).resolve; -var readFile = require( '@stdlib/fs-read-file' ); -var reduceRightAsync = require( './../lib' ); - -var files = [ - resolve( __dirname, '..', 'package.json' ), - resolve( __dirname, '..', 'README.md' ) -]; - -function done( error, acc ) { - if ( error ) { - throw error; - } - console.log( acc.count ); -} - -function read( acc, file, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( file, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( null, acc ); - } - acc.count += 1; - next( null, acc ); - } -} - -var acc = { - 'count': 0 -}; -reduceRightAsync( files, acc, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 28e0a36..f6cba5d 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..ab01fae --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import{isPrimitive as c}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.1-esm/index.mjs";function m(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var d=m(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function f(e,m){var f,u,p;if(f={},arguments.length>1){if(u=function(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("1RZ2o","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!c(e.limit))?new TypeError(r("1RZ3P","limit",e.limit)):null):new TypeError(r("1RZ2V",t))}(f,e),u)throw u;p=m}else p=e;if(!t(p))throw new TypeError(r("1RZ3q",p));return void 0===f.series&&void 0===f.limit&&(f.series=!0),f.series?f.limit=1:f.limit||(f.limit=s),function(e,s,n){if(!i(e))throw new TypeError(r("1RZAh",e));if(!t(n))throw new TypeError(r("1RZ3q",n));return function(e,t,i,r,s){var n,o,l,c,m,f;if(c=e.length,d("Collection length: %d",c),0===c)return d("Finished processing a collection."),s(null,t);for(l=c0&&u();function u(){function s(e,i){if(!o){if(e)return o=!0,p(e);d("Accumulator: %s",JSON.stringify(i)),t=i,p()}}d("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function p(e){return e?(d("Encountered an error: %s",e.message),s(e)):(d("Processed %d of %d collection elements.",n+=1,c),m>0?u():n===c?(d("Finished processing a collection."),s(null,t)):void 0)}}(e,s,f,p,(function(e,t){if(e)return n(e);n(null,t)}))}}function u(e,t,i,r,s){if(arguments.length<5)return f(i)(e,t,r);f(i,r)(e,t,s)}e(u,"factory",f);export{u as default,f as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..e11f2cb --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/limit.js","../lib/factory.js","../lib/validate.js","../lib/main.js","../lib/index.js"],"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 logger = require( 'debug' );\n\n\n// VARIABLES //\n\nvar debug = logger( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RZ3q', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '1RZAh', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RZ3q', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '1RZ2V', 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( '1RZ2o', '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( '1RZ3P', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["debug","logger","factory","options","fcn","opts","err","f","arguments","length","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","validate","isFunction","PINF","collection","initial","done","isCollection","acc","count","flg","lim","len","idx","i","next","cb","error","result","clbk","JSON","stringify","call","message","reduceRightAsync","setReadOnly","main"],"mappings":";;81CA2BIA,uDAAQC,CAAQ,4BCoEpB,SAASC,EAASC,EAASC,GAC1B,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAA,EACFG,UAAUC,OAAS,EAAI,CAE3B,GADAH,EChDF,SAAmBD,EAAMF,GACxB,OAAMO,EAAUP,IAGXQ,EAAYR,EAAS,aACzBE,EAAKO,QAAUT,EAAQS,SAEnBD,EAAYR,EAAS,YACzBE,EAAKQ,OAASV,EAAQU,QAChBC,EAAWT,EAAKQ,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUX,EAAKQ,SAGnDF,EAAYR,EAAS,WACzBE,EAAKY,MAAQd,EAAQc,OACfC,EAAmBb,EAAKY,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASX,EAAKY,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASb,GAkBzC,CD4BQgB,CAAUd,EAAMF,GACjBG,EACJ,MAAMA,EAEPC,EAAIH,CACN,MACEG,EAAIJ,EAEL,IAAMiB,EAAYb,GACjB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAUvC,YARqB,IAAhBF,EAAKQ,aAAoC,IAAfR,EAAKY,QACnCZ,EAAKQ,QAAS,GAEVR,EAAKQ,OACTR,EAAKY,MAAQ,EACDZ,EAAKY,QACjBZ,EAAKY,MAAQI,GAed,SAA2BC,EAAYC,EAASC,GAC/C,IAAMC,EAAcH,GACnB,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,IAAMF,EAAYI,GACjB,MAAM,IAAIT,UAAWC,EAAQ,QAASQ,IAEvC,ODhGF,SAAgBF,EAAYI,EAAKrB,EAAMD,EAAKoB,GAC3C,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMR,EAAWb,OACjBT,EAAO,wBAAyB8B,GAEnB,IAARA,EAEJ,OADA9B,EAAO,qCACAwB,EAAM,KAAME,GAYpB,IATCG,EADIC,EAAMzB,EAAKY,MACTa,EAEAzB,EAAKY,MAEZjB,EAAO,wBAAyB6B,GAChC7B,EAAO,0BAA2BI,EAAIK,QAEtCkB,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVE,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKR,EAAL,CAIA,GAAKO,EAEJ,OADAP,GAAM,EACCS,EAAMF,GAEdnC,EAAO,kBAAmBsC,KAAKC,UAAWH,IAC1CV,EAAMU,EACNC,GAPC,CAQD,CA5BDrC,EAAO,6BADP+B,GAAO,EACmCO,KAAKC,UAAWjB,EAAYS,KAClD,IAAf3B,EAAIK,OACRL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOG,GACtB,IAAf9B,EAAIK,OACfL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKG,GAErD9B,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKT,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJnC,EAAO,2BAA4BmC,EAAMM,SAClCjB,EAAMW,KAGdnC,EAAO,0CADP2B,GAAS,EACgDG,GACpDC,EAAM,EACHE,IAEHN,IAAUG,GACd9B,EAAO,qCACAwB,EAAM,KAAME,SAFpB,EAIA,CACF,CCKST,CAAOK,EAAYC,EAASlB,EAAME,GAUzC,SAAe4B,EAAOT,GACrB,GAAKS,EACJ,OAAOX,EAAMW,GAEdX,EAAM,KAAME,EACZ,GACD,CACF,CE1EA,SAASgB,EAAkBpB,EAAYC,EAASpB,EAASC,EAAKoB,GAC7D,GAAKhB,UAAUC,OAAS,EACvB,OAAOP,EAASC,EAATD,CAAoBoB,EAAYC,EAASnB,GAEjDF,EAASC,EAASC,EAAlBF,CAAyBoB,EAAYC,EAASC,EAC/C,CClBAmB,EAAAC,EAAA,UAAA1C"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index e107128..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,164 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var validate = require( './validate.js' ); -var limit = require( './limit.js' ); - - -// MAIN // - -/** -* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} last argument must be a function -* @returns {Function} function which invokes the provided function once for each element in a collection -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error, data ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var opts = { -* 'series': false -* }; -* -* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: -* var reduceRightAsync = factory( opts, read ); -* -* // Create a collection over which to iterate: -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* // Define a callback which handles errors: -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* // Run `read` for each element in `files`: -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, done ); -*/ -function factory( options, fcn ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = fcn; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '1RZ3q', f ) ); - } - if ( opts.series === void 0 && opts.limit === void 0 ) { - opts.series = true; - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return reduceRightAsync; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * @private - * @param {Collection} collection - input collection - * @param {*} initial - initial value - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be a collection - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function reduceRightAsync( collection, initial, done ) { - if ( !isCollection( collection ) ) { - throw new TypeError( format( '1RZAh', collection ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '1RZ3q', done ) ); - } - return limit( collection, initial, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {*} [acc] - accumulated value - * @returns {void} - */ - function clbk( error, acc ) { - if ( error ) { - return done( error ); - } - done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ae657ff..0000000 --- a/lib/index.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* @module @stdlib/utils-async-reduce-right -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' ); -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/limit.js b/lib/limit.js deleted file mode 100644 index cdb60af..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); - - -// VARIABLES // - -var debug = logger( 'reduce-right-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each element in a collection, limiting the number of concurrently pending functions and iterating from right to left. -* -* @private -* @param {Collection} collection - input collection -* @param {*} acc - initial value -* @param {Options} opts - function options -* @param {*} [opts.thisArg] - execution context -* @param {PositiveInteger} [opts.limit] - maximum number of pending function invocations -* @param {Function} fcn - function to invoke -* @param {Callback} done - function to invoke upon completion or upon encountering an error -* @returns {void} -*/ -function limit( collection, acc, opts, fcn, done ) { - var count; - var flg; - var lim; - var len; - var idx; - var i; - - len = collection.length; - debug( 'Collection length: %d', len ); - - if ( len === 0 ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - count = 0; - idx = len; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all collection elements... - if ( idx > 0 ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next element in a collection. - * - * @private - */ - function next() { - idx -= 1; - debug( 'Collection element %d: %s.', idx, JSON.stringify( collection[ idx ] ) ); - if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], cb ); - } else if ( fcn.length === 4 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, cb ); - } else { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len - } - /** - * Callback invoked once a provided function finishes processing a collection element. - * - * @private - * @param {*} [error] - error - * @param {*} [result] - accumulation result - * @returns {void} - */ - function cb( error, result ) { - if ( flg ) { - // Prevent further processing of collection elements: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Accumulator: %s', JSON.stringify( result ) ); - acc = result; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next collection element. - * - * @private - * @param {*} [error] - error - * @returns {void} - */ - function clbk( error ) { - if ( error ) { - debug( 'Encountered an error: %s', error.message ); - return done( error ); - } - count += 1; - debug( 'Processed %d of %d collection elements.', count, len ); - if ( idx > 0 ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index c8b0d0f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param {Collection} collection - input collection -* @param {*} initial - initial value -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} second-to-last argument must be a function -* @throws {TypeError} last argument must be a function -* @returns {void} -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -function reduceRightAsync( collection, initial, options, fcn, done ) { - if ( arguments.length < 5 ) { - return factory( options )( collection, initial, fcn ); - } - factory( options, fcn )( collection, initial, done ); -} - - -// EXPORTS // - -module.exports = reduceRightAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 0c666fe..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @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 -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'thisArg': {}, -* 'series': false, -* 'limit': 10 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '1RZ2V', options ) ); - } - if ( hasOwnProp( options, 'thisArg' ) ) { - opts.thisArg = options.thisArg; - } - if ( hasOwnProp( options, 'series' ) ) { - opts.series = options.series; - if ( !isBoolean( opts.series ) ) { - return new TypeError( format( '1RZ2o', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '1RZ3P', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index eaf0e2f..3464c63 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,44 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-boolean": "^0.2.1", - "@stdlib/assert-is-collection": "^0.2.1", - "@stdlib/assert-is-function": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/assert-is-positive-integer": "^0.2.1", - "@stdlib/constants-float64-pinf": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", - "debug": "^2.6.9", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/constants-float64-eps": "^0.2.1", - "@stdlib/fs-read-file": "^0.2.1", - "@stdlib/utils-noop": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..9a829df --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 8244931..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1095 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( {}, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, next ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - factory( opts, next ); - }; - } -}); - -tape( 'the function returns a function (no options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided a collection (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a collection (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (1 argument)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (2 arguments)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with five arguments', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn() { - var value; - var next; - var acc; - var k; - - acc = arguments[ 0 ]; - value = arguments[ 1 ]; - k = arguments[ 2 ]; - next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( k, i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the returned function supports processing collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements concurrently', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 100, 250, 300 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements sequentially (limit = 1)', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of collection elements which are processed at any one time', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 250, 300, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 250, 100, 300 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var reduceRightAsync; - var arr; - - reduceRightAsync = factory( fcn ); - arr = []; - - reduceRightAsync( arr, 0, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var reduceRightAsync; - var obj; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = []; - obj = {}; - reduceRightAsync( arr, obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - i = 0; - - reduceRightAsync( arr, {}, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, acc ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the returned function does not skip empty elements', function test( t ) { - var reduceRightAsync; - var expected; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index f273a40..0000000 --- a/test/test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof reduceRightAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 1893240..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1035 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a collection', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (no options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, next, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, 0 ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - reduceRightAsync( [ 1, 2, 3 ], 0, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (1 argument)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (2 arguments)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with five arguments', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn() { - var next; - var acc; - var v; - - next = arguments[ 4 ]; - acc = arguments[ 0 ]; - v = arguments[ 1 ]; - - i -= 1; - j += 1; - - t.strictEqual( v, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, v ); - - function onTimeout() { - acc.sum += v; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'by default, the function processes collection elements sequentially', function test( t ) { - var values; - var count; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements concurrently', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 100, 250, 300 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': true - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially (limit = 1)', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var arr; - var ctx; - - arr = [ 3, 2, 1 ]; - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 3, 2, 1 ]; - opts = { - 'series': true - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 250, 100, 300 ]; - opts = { - 'limit': 2 - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var arr = []; - reduceRightAsync( arr, 0, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var arr = []; - var obj = {}; - - reduceRightAsync( arr, obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - arr = [ 3, 2, 1 ]; - i = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, value ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the function does not skip empty elements', function test( t ) { - var expected; - var arr; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, fcn, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 7660838..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,181 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `limit` option which is not a positive integer', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - -5, - 0, - 3.14, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'limit': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `series` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'series': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function accepts any value for the `thisArg` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'thisArg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err, null, 'returns null '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'thisArg': {}, - 'series': false, - 'limit': 10 - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From 87b7923953cf869cc9297166a1dba5c97b1c3432 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 28 Jul 2024 00:13:59 +0000 Subject: [PATCH 113/147] Transform error messages --- lib/factory.js | 8 ++++---- lib/validate.js | 8 ++++---- package.json | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 1125052..e107128 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -22,7 +22,7 @@ var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var PINF = require( '@stdlib/constants-float64-pinf' ); var validate = require( './validate.js' ); var limit = require( './limit.js' ); @@ -109,7 +109,7 @@ function factory( options, fcn ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '1RZ3q', f ) ); } if ( opts.series === void 0 && opts.limit === void 0 ) { opts.series = true; @@ -134,10 +134,10 @@ function factory( options, fcn ) { */ function reduceRightAsync( collection, initial, done ) { if ( !isCollection( collection ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a collection. Value: `%s`.', collection ) ); + throw new TypeError( format( '1RZAh', collection ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '1RZ3q', done ) ); } return limit( collection, initial, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index 9ba927e..0c666fe 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,7 +54,7 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '1RZ2V', options ) ); } if ( hasOwnProp( options, 'thisArg' ) ) { opts.thisArg = options.thisArg; @@ -62,13 +62,13 @@ function validate( opts, options ) { if ( hasOwnProp( options, 'series' ) ) { opts.series = options.series; if ( !isBoolean( opts.series ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'series', opts.series ) ); + return new TypeError( format( '1RZ2o', 'series', opts.series ) ); } } if ( hasOwnProp( options, 'limit' ) ) { opts.limit = options.limit; if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'limit', opts.limit ) ); + return new TypeError( format( '1RZ3P', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index 50ae07e..7d5304d 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-plain-object": "^0.2.2", "@stdlib/assert-is-positive-integer": "^0.2.2", "@stdlib/constants-float64-pinf": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.3.2", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", "debug": "^2.6.9", From 16d9d2d77ba3b0515c20d4bcf1905fbe8727902a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 28 Jul 2024 00:19:16 +0000 Subject: [PATCH 114/147] Remove files --- index.d.ts | 410 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5257 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index f6cba5d..0000000 --- a/index.d.ts +++ /dev/null @@ -1,410 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Execution context. - */ - thisArg?: ThisParameterType>; - - /** - * The maximum number of pending invocations at any one time. - */ - limit?: number; - - /** - * Boolean indicating whether to sequentially invoke the reducer function for each `collection` element. If `true`, the function sets `options.limit=1`. Default: true. - */ - series?: boolean; -} - -/** -* Callback function. -*/ -type Nullary = () => void; - -/** -* Callback function. -* -* @param error - encountered error or null -*/ -type Unary = ( error: Error | null ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Binary = ( error: Error | null, accumulator: U ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param next - a callback to be invoked after processing a collection `value` -*/ -type TernaryReducer = ( this: V, accumulator: U, value: T, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuaternaryReducer = ( this: V, accumulator: U, value: T, index: number, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuinaryReducer = ( this: V, accumulator: U, value: T, index: number, collection: Collection, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type Reducer = TernaryReducer | QuaternaryReducer | QuinaryReducer; - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result. -* -* @param collection - input collection -* @param initial - initial value -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( collection: Collection, initial: U, done: Callback ) => void; - -/** -* Interface for `reduceRightAsync`. -*/ -interface ReduceRightAsync { - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, {}, read, done ); - */ - ( collection: Collection, initial: U, options: Options, reducer: Reducer, done: Callback ): void; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, read, done ); - */ - ( collection: Collection, initial: U, reducer: Reducer, done: Callback ): void; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @throws must provide valid options - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var opts = { - * 'series': false - * }; - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( opts, read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( options: Options, reducer: Reducer ): FactoryFunction; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param reducer - function to invoke for each element in a collection - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( reducer: Reducer ): FactoryFunction; -} - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param collection - input collection -* @param initial - initial value -* @param options - function options -* @param options.thisArg - execution context -* @param options.limit - maximum number of pending invocations at any one time -* @param 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 (default: true) -* @param reducer - function to invoke for each element in a collection -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -declare var reduceRightAsync: ReduceRightAsync; - - -// EXPORTS // - -export = reduceRightAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index ab01fae..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import{isPrimitive as c}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.1-esm/index.mjs";function m(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var d=m(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function f(e,m){var f,u,p;if(f={},arguments.length>1){if(u=function(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("1RZ2o","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!c(e.limit))?new TypeError(r("1RZ3P","limit",e.limit)):null):new TypeError(r("1RZ2V",t))}(f,e),u)throw u;p=m}else p=e;if(!t(p))throw new TypeError(r("1RZ3q",p));return void 0===f.series&&void 0===f.limit&&(f.series=!0),f.series?f.limit=1:f.limit||(f.limit=s),function(e,s,n){if(!i(e))throw new TypeError(r("1RZAh",e));if(!t(n))throw new TypeError(r("1RZ3q",n));return function(e,t,i,r,s){var n,o,l,c,m,f;if(c=e.length,d("Collection length: %d",c),0===c)return d("Finished processing a collection."),s(null,t);for(l=c0&&u();function u(){function s(e,i){if(!o){if(e)return o=!0,p(e);d("Accumulator: %s",JSON.stringify(i)),t=i,p()}}d("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function p(e){return e?(d("Encountered an error: %s",e.message),s(e)):(d("Processed %d of %d collection elements.",n+=1,c),m>0?u():n===c?(d("Finished processing a collection."),s(null,t)):void 0)}}(e,s,f,p,(function(e,t){if(e)return n(e);n(null,t)}))}}function u(e,t,i,r,s){if(arguments.length<5)return f(i)(e,t,r);f(i,r)(e,t,s)}e(u,"factory",f);export{u as default,f as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index e11f2cb..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/limit.js","../lib/factory.js","../lib/validate.js","../lib/main.js","../lib/index.js"],"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 logger = require( 'debug' );\n\n\n// VARIABLES //\n\nvar debug = logger( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RZ3q', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '1RZAh', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RZ3q', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '1RZ2V', 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( '1RZ2o', '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( '1RZ3P', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["debug","logger","factory","options","fcn","opts","err","f","arguments","length","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","validate","isFunction","PINF","collection","initial","done","isCollection","acc","count","flg","lim","len","idx","i","next","cb","error","result","clbk","JSON","stringify","call","message","reduceRightAsync","setReadOnly","main"],"mappings":";;81CA2BIA,uDAAQC,CAAQ,4BCoEpB,SAASC,EAASC,EAASC,GAC1B,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAA,EACFG,UAAUC,OAAS,EAAI,CAE3B,GADAH,EChDF,SAAmBD,EAAMF,GACxB,OAAMO,EAAUP,IAGXQ,EAAYR,EAAS,aACzBE,EAAKO,QAAUT,EAAQS,SAEnBD,EAAYR,EAAS,YACzBE,EAAKQ,OAASV,EAAQU,QAChBC,EAAWT,EAAKQ,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUX,EAAKQ,SAGnDF,EAAYR,EAAS,WACzBE,EAAKY,MAAQd,EAAQc,OACfC,EAAmBb,EAAKY,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASX,EAAKY,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASb,GAkBzC,CD4BQgB,CAAUd,EAAMF,GACjBG,EACJ,MAAMA,EAEPC,EAAIH,CACN,MACEG,EAAIJ,EAEL,IAAMiB,EAAYb,GACjB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAUvC,YARqB,IAAhBF,EAAKQ,aAAoC,IAAfR,EAAKY,QACnCZ,EAAKQ,QAAS,GAEVR,EAAKQ,OACTR,EAAKY,MAAQ,EACDZ,EAAKY,QACjBZ,EAAKY,MAAQI,GAed,SAA2BC,EAAYC,EAASC,GAC/C,IAAMC,EAAcH,GACnB,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,IAAMF,EAAYI,GACjB,MAAM,IAAIT,UAAWC,EAAQ,QAASQ,IAEvC,ODhGF,SAAgBF,EAAYI,EAAKrB,EAAMD,EAAKoB,GAC3C,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMR,EAAWb,OACjBT,EAAO,wBAAyB8B,GAEnB,IAARA,EAEJ,OADA9B,EAAO,qCACAwB,EAAM,KAAME,GAYpB,IATCG,EADIC,EAAMzB,EAAKY,MACTa,EAEAzB,EAAKY,MAEZjB,EAAO,wBAAyB6B,GAChC7B,EAAO,0BAA2BI,EAAIK,QAEtCkB,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVE,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKR,EAAL,CAIA,GAAKO,EAEJ,OADAP,GAAM,EACCS,EAAMF,GAEdnC,EAAO,kBAAmBsC,KAAKC,UAAWH,IAC1CV,EAAMU,EACNC,GAPC,CAQD,CA5BDrC,EAAO,6BADP+B,GAAO,EACmCO,KAAKC,UAAWjB,EAAYS,KAClD,IAAf3B,EAAIK,OACRL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOG,GACtB,IAAf9B,EAAIK,OACfL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKG,GAErD9B,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKT,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJnC,EAAO,2BAA4BmC,EAAMM,SAClCjB,EAAMW,KAGdnC,EAAO,0CADP2B,GAAS,EACgDG,GACpDC,EAAM,EACHE,IAEHN,IAAUG,GACd9B,EAAO,qCACAwB,EAAM,KAAME,SAFpB,EAIA,CACF,CCKST,CAAOK,EAAYC,EAASlB,EAAME,GAUzC,SAAe4B,EAAOT,GACrB,GAAKS,EACJ,OAAOX,EAAMW,GAEdX,EAAM,KAAME,EACZ,GACD,CACF,CE1EA,SAASgB,EAAkBpB,EAAYC,EAASpB,EAASC,EAAKoB,GAC7D,GAAKhB,UAAUC,OAAS,EACvB,OAAOP,EAASC,EAATD,CAAoBoB,EAAYC,EAASnB,GAEjDF,EAASC,EAASC,EAAlBF,CAAyBoB,EAAYC,EAASC,EAC/C,CClBAmB,EAAAC,EAAA,UAAA1C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 9a829df..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 59816fec95094950cdf13b3fd0b13ea66076931f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 28 Jul 2024 00:19:28 +0000 Subject: [PATCH 115/147] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 212 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.factory.js | 73 - benchmark/benchmark.js | 160 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 224 - docs/types/test.ts | 166 - examples/index.js | 55 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 164 - lib/index.js | 77 - lib/limit.js | 142 - lib/main.js | 95 - lib/validate.js | 80 - package.json | 65 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 1095 ----- test/test.js | 38 - test/test.main.js | 1035 ----- test/test.validate.js | 181 - 49 files changed, 4873 insertions(+), 7175 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/limit.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1e08946..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 5358060..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index fa37f2d..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '37 1 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -460,7 +457,7 @@ reduceRightAsync( files, acc, read, done ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -531,11 +528,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right +[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right/tree/esm -[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce +[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index b155fd2..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var reduceRightAsync; - var arr; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - reduceRightAsync = factory( onItem ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - var acc; - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index af5c346..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var reduceRightAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=false', function benchmark( b ) { - var opts; - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'series': false - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var arr; - var len; - var acc; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'limit': 3 - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b8adcd2..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right" -%% click B href "https://github.com/stdlib-js/utils-async-reduce-right/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-reduce-right/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-reduce-right/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-reduce-right/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right -[production-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-async-reduce-right/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-async-reduce-right/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-async-reduce-right/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 47a072e..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import reduceRightAsync from '../docs/types/index'; -export = reduceRightAsync; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 530ca4d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var c=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var x=c(function(U,O){ -var R=require('@stdlib/assert-is-plain-object/dist'),h=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,k=require('@stdlib/assert-is-positive-integer/dist').isPrimitive,d=require('@stdlib/error-tools-fmtprodmsg/dist');function I(e,r){return R(r)?(h(r,"thisArg")&&(e.thisArg=r.thisArg),h(r,"series")&&(e.series=r.series,!j(e.series))?new TypeError(d('1RZ2o',"series",e.series)):h(r,"limit")&&(e.limit=r.limit,!k(e.limit))?new TypeError(d('1RZ3P',"limit",e.limit)):null):new TypeError(d('1RZ2V',r));}O.exports=I -});var P=c(function(W,E){ -var J=require("debug"),a=J("reduce-right-async:limit");function L(e,r,i,t,s){var f,m,v,n,u,g;if(n=e.length,a("Collection length: %d",n),n===0)return a("Finished processing a collection."),s(null,r);for(n0&&o();function o(){u-=1,a("Collection element %d: %s.",u,JSON.stringify(e[u])),t.length===3?t.call(i.thisArg,r,e[u],l):t.length===4?t.call(i.thisArg,r,e[u],u,l):t.call(i.thisArg,r,e[u],u,e,l);function l(w,A){if(!m){if(w)return m=!0,b(w);a("Accumulator: %s",JSON.stringify(A)),r=A,b()}}}function b(l){if(l)return a("Encountered an error: %s",l.message),s(l);if(f+=1,a("Processed %d of %d collection elements.",f,n),u>0)return o();if(f===n)return a("Finished processing a collection."),s(null,r)}}E.exports=L -});var q=c(function(X,F){ -var T=require('@stdlib/assert-is-function/dist'),S=require('@stdlib/assert-is-collection/dist'),y=require('@stdlib/error-tools-fmtprodmsg/dist'),B=require('@stdlib/constants-float64-pinf/dist'),z=x(),D=P();function G(e,r){var i,t,s;if(i={},arguments.length>1){if(t=z(i,e),t)throw t;s=r}else s=e;if(!T(s))throw new TypeError(y('1RZ3q',s));return i.series===void 0&&i.limit===void 0&&(i.series=!0),i.series?i.limit=1:i.limit||(i.limit=B),f;function f(m,v,n){if(!S(m))throw new TypeError(y('1RZAh',m));if(!T(n))throw new TypeError(y('1RZ3q',n));return D(m,v,i,s,u);function u(g,o){if(g)return n(g);n(null,o)}}}F.exports=G -});var N=c(function(Y,C){ -var p=q();function H(e,r,i,t,s){if(arguments.length<5)return p(i)(e,r,t);p(i,t)(e,r,s)}C.exports=H -});var K=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),V=N(),M=q();K(V,"factory",M);module.exports=V; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index acb9d67..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/limit.js", "../lib/factory.js", "../lib/main.js", "../lib/index.js"], - "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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\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 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 to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\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 === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, 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 ( !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, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\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* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nmodule.exports = reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' );\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, 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"], - "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,0BAA2B,EAkB/C,SAASE,EAAOC,EAAYC,EAAKC,EAAMC,EAAKC,EAAO,CAClD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMR,EAAW,OACjBF,EAAO,wBAAyBU,CAAI,EAE/BA,IAAQ,EACZ,OAAAV,EAAO,mCAAoC,EACpCM,EAAM,KAAMH,CAAI,EAYxB,IAVKO,EAAMN,EAAK,MACfK,EAAMC,EAEND,EAAML,EAAK,MAEZJ,EAAO,wBAAyBS,CAAI,EACpCT,EAAO,0BAA2BK,EAAI,MAAO,EAE7CE,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVE,EAAK,EAQP,SAASA,GAAO,CACfF,GAAO,EACPX,EAAO,6BAA8BW,EAAK,KAAK,UAAWT,EAAYS,CAAI,CAAE,CAAE,EACzEN,EAAI,SAAW,EACnBA,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGG,CAAG,EACxCT,EAAI,SAAW,EAC1BA,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGA,EAAKG,CAAG,EAExDT,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGA,EAAKT,EAAYY,CAAG,EAUrE,SAASA,EAAIC,EAAOC,EAAS,CAC5B,GAAK,CAAAR,EAIL,IAAKO,EACJ,OAAAP,EAAM,GACCS,EAAMF,CAAM,EAEpBf,EAAO,kBAAmB,KAAK,UAAWgB,CAAO,CAAE,EACnDb,EAAMa,EACNC,EAAK,EACN,CACD,CASA,SAASA,EAAMF,EAAQ,CACtB,GAAKA,EACJ,OAAAf,EAAO,2BAA4Be,EAAM,OAAQ,EAC1CT,EAAMS,CAAM,EAIpB,GAFAR,GAAS,EACTP,EAAO,0CAA2CO,EAAOG,CAAI,EACxDC,EAAM,EACV,OAAOE,EAAK,EAEb,GAAKN,IAAUG,EACd,OAAAV,EAAO,mCAAoC,EACpCM,EAAM,KAAMH,CAAI,CAEzB,CACD,CAKAL,EAAO,QAAUG,IC7IjB,IAAAiB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,gCAAiC,EACjDC,EAAW,IACXC,EAAQ,IAoEZ,SAASC,EAASC,EAASC,EAAM,CAChC,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,CAACP,EAAYW,CAAE,EACnB,MAAM,IAAI,UAAWT,EAAQ,mEAAoES,CAAE,CAAE,EAEtG,OAAKF,EAAK,SAAW,QAAUA,EAAK,QAAU,SAC7CA,EAAK,OAAS,IAEVA,EAAK,OACTA,EAAK,MAAQ,EACDA,EAAK,QACjBA,EAAK,MAAQN,GAEPS,EAaP,SAASA,EAAkBC,EAAYC,EAASC,EAAO,CACtD,GAAK,CAACd,EAAcY,CAAW,EAC9B,MAAM,IAAI,UAAWX,EAAQ,sEAAuEW,CAAW,CAAE,EAElH,GAAK,CAACb,EAAYe,CAAK,EACtB,MAAM,IAAI,UAAWb,EAAQ,mEAAoEa,CAAK,CAAE,EAEzG,OAAOV,EAAOQ,EAAYC,EAASL,EAAME,EAAGK,CAAK,EAUjD,SAASA,EAAMC,EAAOC,EAAM,CAC3B,GAAKD,EACJ,OAAOF,EAAME,CAAM,EAEpBF,EAAM,KAAMG,CAAI,CACjB,CACD,CACD,CAKAnB,EAAO,QAAUO,ICnKjB,IAAAa,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,IA8Dd,SAASC,EAAkBC,EAAYC,EAASC,EAASC,EAAKC,EAAO,CACpE,GAAK,UAAU,OAAS,EACvB,OAAON,EAASI,CAAQ,EAAGF,EAAYC,EAASE,CAAI,EAErDL,EAASI,EAASC,CAAI,EAAGH,EAAYC,EAASG,CAAK,CACpD,CAKAP,EAAO,QAAUE,IC9BjB,IAAIM,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "isPositiveInteger", "format", "validate", "opts", "options", "require_limit", "__commonJSMin", "exports", "module", "logger", "debug", "limit", "collection", "acc", "opts", "fcn", "done", "count", "flg", "lim", "len", "idx", "i", "next", "cb", "error", "result", "clbk", "require_factory", "__commonJSMin", "exports", "module", "isFunction", "isCollection", "format", "PINF", "validate", "limit", "factory", "options", "fcn", "opts", "err", "f", "reduceRightAsync", "collection", "initial", "done", "clbk", "error", "acc", "require_main", "__commonJSMin", "exports", "module", "factory", "reduceRightAsync", "collection", "initial", "options", "fcn", "done", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3f22669..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,224 +0,0 @@ - -{{alias}}( collection, initial, [options,] reducer, done ) - Applies a function against an accumulator and each element in a collection - and returns the accumulated result, iterating from right to left. - - When invoked, `reducer` is provided a maximum of five arguments: - - - `accumulator`: accumulated value - - `value`: collection value - - `index`: collection index - - `collection`: the input collection - - `next`: a callback to be invoked after processing a collection `value` - - The actual number of provided arguments depends on function length. If - `reducer` accepts three arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `next` - - If `reducer` accepts four arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `index` - - `next` - - For every other `reducer` signature, `reducer` is provided all five - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `accumulator`: accumulated value - - If a provided function calls the `next` callback with a truthy `error` - argument, the function suspends execution and immediately calls the `done` - callback for subsequent `error` handling. - - Execution is *not* guaranteed to be asynchronous. To guarantee asynchrony, - 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`). - - The function does not support dynamic collection resizing. - - If provided an empty collection, the function invokes the `done` callback - with the `initial` value as the second argument. - - The function does not skip `undefined` elements. - - When processing collection elements concurrently, *beware* of race - conditions when updating an accumulator. This is especially true when an - accumulator is a primitive (e.g., a number). In general, prefer object - accumulators. - - Parameters - ---------- - collection: Array|TypedArray|Object - Input collection over which to iterate. If provided an object, the - object must be array-like (excluding strings and functions). - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - reducer: Function - The function to invoke for each element in a collection. - - done: Function - A callback invoked either upon processing all collection elements or - upon encountering an error. - - Examples - -------- - // Basic usage: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, fcn, done ) - 3000 - 2500 - 1000 - 6500 - - // Limit number of concurrent invocations: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'limit': 2 }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 2500 - 3000 - 1000 - 6500 - - // Process concurrently: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'series': false }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 1000 - 2500 - 3000 - 6500 - - -{{alias}}.factory( [options,] fcn ) - Returns a function which applies a function against an accumulator and each - element in a collection and returns the accumulated result, iterating from - right to left. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - fcn: Function - The function to invoke for each element in a collection. - - Returns - ------- - out: Function - A function which invokes a function for each element in a collection. - - Examples - -------- - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > var opts = { 'series': false }; - > var f = {{alias}}.factory( opts, fcn ); - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > f( arr, acc, done ) - 1000 - 2500 - 3000 - 6500 - > acc = { 'sum': 0 }; - > arr = [ 1000, 1500, 2000 ]; - > f( arr, acc, done ) - 1000 - 1500 - 2000 - 4500 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0455864..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,166 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unsafe-assignment */ - -import reduceRightAsync = require( './index' ); - -const reducer = ( acc: any, value: number, index: number, next: Function ) => { - acc.sum += value; - if ( index === void 0 ) { - throw new Error( '`index` is missing.' ); - } - next( null, acc ); -}; - -const done = ( error: Error | null, acc: any ) => { - if ( error ) { - throw error; - } - if ( acc === void 0 ) { - throw new Error( '`acc` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( 2, acc, reducer, done ); // $ExpectError - reduceRightAsync( false, acc, reducer, done ); // $ExpectError - reduceRightAsync( true, acc, reducer, done ); // $ExpectError - reduceRightAsync( {}, acc, reducer, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a predicate argument which is not a predicate function... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 2, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, false, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, true, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 'abc', done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, [], done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a done callback argument which is not a function having a supported signature... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 2 ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, false ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, true ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 'abc' ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, {} ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, [] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const acc = { 'sum': 0 }; - reduceRightAsync(); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, reducer, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - reduceRightAsync.factory( reducer ); // $ExpectType FactoryFunction - reduceRightAsync.factory( { 'series': true }, reducer ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - reduceRightAsync.factory( [], reducer ); // $ExpectError - reduceRightAsync.factory( 123, reducer ); // $ExpectError - reduceRightAsync.factory( 'abc', reducer ); // $ExpectError - reduceRightAsync.factory( false, reducer ); // $ExpectError - reduceRightAsync.factory( true, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not a predicate function... -{ - reduceRightAsync.factory( {} ); // $ExpectError - reduceRightAsync.factory( true ); // $ExpectError - reduceRightAsync.factory( false ); // $ExpectError - reduceRightAsync.factory( {}, 123 ); // $ExpectError - reduceRightAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1( 12, acc, done ); // $ExpectError - fcn1( true, acc, done ); // $ExpectError - fcn1( false, acc, done ); // $ExpectError - fcn1( {}, acc, done ); // $ExpectError - - fcn1( [ 3000, 2500, 1000 ], acc, 12 ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, true ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, false ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, '5' ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, {} ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, [] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1(); // $ExpectError - fcn1( [ 3000, 2500, 1000 ] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - reduceRightAsync.factory( { 'limit': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': true }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': false }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - reduceRightAsync.factory( { 'series': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': 12 }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - reduceRightAsync.factory(); // $ExpectError - reduceRightAsync.factory( {}, reducer, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index dd64345..0000000 --- a/examples/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var resolve = require( 'path' ).resolve; -var readFile = require( '@stdlib/fs-read-file' ); -var reduceRightAsync = require( './../lib' ); - -var files = [ - resolve( __dirname, '..', 'package.json' ), - resolve( __dirname, '..', 'README.md' ) -]; - -function done( error, acc ) { - if ( error ) { - throw error; - } - console.log( acc.count ); -} - -function read( acc, file, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( file, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( null, acc ); - } - acc.count += 1; - next( null, acc ); - } -} - -var acc = { - 'count': 0 -}; -reduceRightAsync( files, acc, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 28e0a36..f6cba5d 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..234a485 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as c}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";function m(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var d=m(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function f(e,m){var f,u,p;if(f={},arguments.length>1){if(u=function(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("1RZ2o","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!c(e.limit))?new TypeError(r("1RZ3P","limit",e.limit)):null):new TypeError(r("1RZ2V",t))}(f,e),u)throw u;p=m}else p=e;if(!t(p))throw new TypeError(r("1RZ3q",p));return void 0===f.series&&void 0===f.limit&&(f.series=!0),f.series?f.limit=1:f.limit||(f.limit=s),function(e,s,n){if(!i(e))throw new TypeError(r("1RZAh",e));if(!t(n))throw new TypeError(r("1RZ3q",n));return function(e,t,i,r,s){var n,o,l,c,m,f;if(c=e.length,d("Collection length: %d",c),0===c)return d("Finished processing a collection."),s(null,t);for(l=c0&&u();function u(){function s(e,i){if(!o){if(e)return o=!0,p(e);d("Accumulator: %s",JSON.stringify(i)),t=i,p()}}d("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function p(e){return e?(d("Encountered an error: %s",e.message),s(e)):(d("Processed %d of %d collection elements.",n+=1,c),m>0?u():n===c?(d("Finished processing a collection."),s(null,t)):void 0)}}(e,s,f,p,(function(e,t){if(e)return n(e);n(null,t)}))}}function u(e,t,i,r,s){if(arguments.length<5)return f(i)(e,t,r);f(i,r)(e,t,s)}e(u,"factory",f);export{u as default,f as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..e11f2cb --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/limit.js","../lib/factory.js","../lib/validate.js","../lib/main.js","../lib/index.js"],"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 logger = require( 'debug' );\n\n\n// VARIABLES //\n\nvar debug = logger( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RZ3q', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '1RZAh', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RZ3q', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '1RZ2V', 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( '1RZ2o', '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( '1RZ3P', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["debug","logger","factory","options","fcn","opts","err","f","arguments","length","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","validate","isFunction","PINF","collection","initial","done","isCollection","acc","count","flg","lim","len","idx","i","next","cb","error","result","clbk","JSON","stringify","call","message","reduceRightAsync","setReadOnly","main"],"mappings":";;81CA2BIA,uDAAQC,CAAQ,4BCoEpB,SAASC,EAASC,EAASC,GAC1B,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAA,EACFG,UAAUC,OAAS,EAAI,CAE3B,GADAH,EChDF,SAAmBD,EAAMF,GACxB,OAAMO,EAAUP,IAGXQ,EAAYR,EAAS,aACzBE,EAAKO,QAAUT,EAAQS,SAEnBD,EAAYR,EAAS,YACzBE,EAAKQ,OAASV,EAAQU,QAChBC,EAAWT,EAAKQ,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUX,EAAKQ,SAGnDF,EAAYR,EAAS,WACzBE,EAAKY,MAAQd,EAAQc,OACfC,EAAmBb,EAAKY,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASX,EAAKY,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASb,GAkBzC,CD4BQgB,CAAUd,EAAMF,GACjBG,EACJ,MAAMA,EAEPC,EAAIH,CACN,MACEG,EAAIJ,EAEL,IAAMiB,EAAYb,GACjB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAUvC,YARqB,IAAhBF,EAAKQ,aAAoC,IAAfR,EAAKY,QACnCZ,EAAKQ,QAAS,GAEVR,EAAKQ,OACTR,EAAKY,MAAQ,EACDZ,EAAKY,QACjBZ,EAAKY,MAAQI,GAed,SAA2BC,EAAYC,EAASC,GAC/C,IAAMC,EAAcH,GACnB,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,IAAMF,EAAYI,GACjB,MAAM,IAAIT,UAAWC,EAAQ,QAASQ,IAEvC,ODhGF,SAAgBF,EAAYI,EAAKrB,EAAMD,EAAKoB,GAC3C,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMR,EAAWb,OACjBT,EAAO,wBAAyB8B,GAEnB,IAARA,EAEJ,OADA9B,EAAO,qCACAwB,EAAM,KAAME,GAYpB,IATCG,EADIC,EAAMzB,EAAKY,MACTa,EAEAzB,EAAKY,MAEZjB,EAAO,wBAAyB6B,GAChC7B,EAAO,0BAA2BI,EAAIK,QAEtCkB,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVE,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKR,EAAL,CAIA,GAAKO,EAEJ,OADAP,GAAM,EACCS,EAAMF,GAEdnC,EAAO,kBAAmBsC,KAAKC,UAAWH,IAC1CV,EAAMU,EACNC,GAPC,CAQD,CA5BDrC,EAAO,6BADP+B,GAAO,EACmCO,KAAKC,UAAWjB,EAAYS,KAClD,IAAf3B,EAAIK,OACRL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOG,GACtB,IAAf9B,EAAIK,OACfL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKG,GAErD9B,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKT,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJnC,EAAO,2BAA4BmC,EAAMM,SAClCjB,EAAMW,KAGdnC,EAAO,0CADP2B,GAAS,EACgDG,GACpDC,EAAM,EACHE,IAEHN,IAAUG,GACd9B,EAAO,qCACAwB,EAAM,KAAME,SAFpB,EAIA,CACF,CCKST,CAAOK,EAAYC,EAASlB,EAAME,GAUzC,SAAe4B,EAAOT,GACrB,GAAKS,EACJ,OAAOX,EAAMW,GAEdX,EAAM,KAAME,EACZ,GACD,CACF,CE1EA,SAASgB,EAAkBpB,EAAYC,EAASpB,EAASC,EAAKoB,GAC7D,GAAKhB,UAAUC,OAAS,EACvB,OAAOP,EAASC,EAATD,CAAoBoB,EAAYC,EAASnB,GAEjDF,EAASC,EAASC,EAAlBF,CAAyBoB,EAAYC,EAASC,EAC/C,CClBAmB,EAAAC,EAAA,UAAA1C"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index e107128..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,164 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var validate = require( './validate.js' ); -var limit = require( './limit.js' ); - - -// MAIN // - -/** -* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} last argument must be a function -* @returns {Function} function which invokes the provided function once for each element in a collection -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error, data ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var opts = { -* 'series': false -* }; -* -* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: -* var reduceRightAsync = factory( opts, read ); -* -* // Create a collection over which to iterate: -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* // Define a callback which handles errors: -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* // Run `read` for each element in `files`: -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, done ); -*/ -function factory( options, fcn ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = fcn; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '1RZ3q', f ) ); - } - if ( opts.series === void 0 && opts.limit === void 0 ) { - opts.series = true; - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return reduceRightAsync; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * @private - * @param {Collection} collection - input collection - * @param {*} initial - initial value - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be a collection - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function reduceRightAsync( collection, initial, done ) { - if ( !isCollection( collection ) ) { - throw new TypeError( format( '1RZAh', collection ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '1RZ3q', done ) ); - } - return limit( collection, initial, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {*} [acc] - accumulated value - * @returns {void} - */ - function clbk( error, acc ) { - if ( error ) { - return done( error ); - } - done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ae657ff..0000000 --- a/lib/index.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* @module @stdlib/utils-async-reduce-right -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' ); -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/limit.js b/lib/limit.js deleted file mode 100644 index cdb60af..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); - - -// VARIABLES // - -var debug = logger( 'reduce-right-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each element in a collection, limiting the number of concurrently pending functions and iterating from right to left. -* -* @private -* @param {Collection} collection - input collection -* @param {*} acc - initial value -* @param {Options} opts - function options -* @param {*} [opts.thisArg] - execution context -* @param {PositiveInteger} [opts.limit] - maximum number of pending function invocations -* @param {Function} fcn - function to invoke -* @param {Callback} done - function to invoke upon completion or upon encountering an error -* @returns {void} -*/ -function limit( collection, acc, opts, fcn, done ) { - var count; - var flg; - var lim; - var len; - var idx; - var i; - - len = collection.length; - debug( 'Collection length: %d', len ); - - if ( len === 0 ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - count = 0; - idx = len; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all collection elements... - if ( idx > 0 ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next element in a collection. - * - * @private - */ - function next() { - idx -= 1; - debug( 'Collection element %d: %s.', idx, JSON.stringify( collection[ idx ] ) ); - if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], cb ); - } else if ( fcn.length === 4 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, cb ); - } else { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len - } - /** - * Callback invoked once a provided function finishes processing a collection element. - * - * @private - * @param {*} [error] - error - * @param {*} [result] - accumulation result - * @returns {void} - */ - function cb( error, result ) { - if ( flg ) { - // Prevent further processing of collection elements: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Accumulator: %s', JSON.stringify( result ) ); - acc = result; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next collection element. - * - * @private - * @param {*} [error] - error - * @returns {void} - */ - function clbk( error ) { - if ( error ) { - debug( 'Encountered an error: %s', error.message ); - return done( error ); - } - count += 1; - debug( 'Processed %d of %d collection elements.', count, len ); - if ( idx > 0 ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index c8b0d0f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param {Collection} collection - input collection -* @param {*} initial - initial value -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} second-to-last argument must be a function -* @throws {TypeError} last argument must be a function -* @returns {void} -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -function reduceRightAsync( collection, initial, options, fcn, done ) { - if ( arguments.length < 5 ) { - return factory( options )( collection, initial, fcn ); - } - factory( options, fcn )( collection, initial, done ); -} - - -// EXPORTS // - -module.exports = reduceRightAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 0c666fe..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @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 -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'thisArg': {}, -* 'series': false, -* 'limit': 10 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '1RZ2V', options ) ); - } - if ( hasOwnProp( options, 'thisArg' ) ) { - opts.thisArg = options.thisArg; - } - if ( hasOwnProp( options, 'series' ) ) { - opts.series = options.series; - if ( !isBoolean( opts.series ) ) { - return new TypeError( format( '1RZ2o', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '1RZ3P', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 7d5304d..563c57c 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,44 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-collection": "^0.2.1", - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/assert-is-positive-integer": "^0.2.2", - "@stdlib/constants-float64-pinf": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "debug": "^2.6.9", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/constants-float64-eps": "^0.2.2", - "@stdlib/fs-read-file": "^0.2.2", - "@stdlib/utils-noop": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..69bcdc8 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 8244931..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1095 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( {}, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, next ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - factory( opts, next ); - }; - } -}); - -tape( 'the function returns a function (no options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided a collection (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a collection (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (1 argument)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (2 arguments)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with five arguments', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn() { - var value; - var next; - var acc; - var k; - - acc = arguments[ 0 ]; - value = arguments[ 1 ]; - k = arguments[ 2 ]; - next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( k, i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the returned function supports processing collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements concurrently', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 100, 250, 300 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements sequentially (limit = 1)', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of collection elements which are processed at any one time', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 250, 300, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 250, 100, 300 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var reduceRightAsync; - var arr; - - reduceRightAsync = factory( fcn ); - arr = []; - - reduceRightAsync( arr, 0, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var reduceRightAsync; - var obj; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = []; - obj = {}; - reduceRightAsync( arr, obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - i = 0; - - reduceRightAsync( arr, {}, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, acc ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the returned function does not skip empty elements', function test( t ) { - var reduceRightAsync; - var expected; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index f273a40..0000000 --- a/test/test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof reduceRightAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 1893240..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1035 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a collection', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (no options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, next, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, 0 ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - reduceRightAsync( [ 1, 2, 3 ], 0, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (1 argument)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (2 arguments)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with five arguments', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn() { - var next; - var acc; - var v; - - next = arguments[ 4 ]; - acc = arguments[ 0 ]; - v = arguments[ 1 ]; - - i -= 1; - j += 1; - - t.strictEqual( v, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, v ); - - function onTimeout() { - acc.sum += v; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'by default, the function processes collection elements sequentially', function test( t ) { - var values; - var count; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements concurrently', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 100, 250, 300 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': true - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially (limit = 1)', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var arr; - var ctx; - - arr = [ 3, 2, 1 ]; - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 3, 2, 1 ]; - opts = { - 'series': true - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 250, 100, 300 ]; - opts = { - 'limit': 2 - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var arr = []; - reduceRightAsync( arr, 0, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var arr = []; - var obj = {}; - - reduceRightAsync( arr, obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - arr = [ 3, 2, 1 ]; - i = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, value ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the function does not skip empty elements', function test( t ) { - var expected; - var arr; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, fcn, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 7660838..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,181 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `limit` option which is not a positive integer', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - -5, - 0, - 3.14, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'limit': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `series` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'series': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function accepts any value for the `thisArg` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'thisArg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err, null, 'returns null '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'thisArg': {}, - 'series': false, - 'limit': 10 - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From fe3ec43ad98ab99611c88896a883393f06c233dd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 28 Jul 2024 00:22:08 +0000 Subject: [PATCH 116/147] Update README.md for ESM bundle v0.2.2 --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9d556b2..bea9a5a 100644 --- a/README.md +++ b/README.md @@ -52,13 +52,13 @@ limitations under the License. ## Usage ```javascript -import reduceRightAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-reduce-right@esm/index.mjs'; +import reduceRightAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-reduce-right@v0.2.2-esm/index.mjs'; ``` You can also import the following named exports from the package: ```javascript -import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-reduce-right@esm/index.mjs'; +import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-reduce-right@v0.2.2-esm/index.mjs'; ``` #### reduceRightAsync( collection, initial, \[options,] reducer, done ) @@ -381,7 +381,7 @@ The function accepts the same `options` as `reduceRightAsync()`. var resolve = require( 'path' ).resolve; import readFile from 'https://cdn.jsdelivr.net/gh/stdlib-js/fs-read-file@esm/index.mjs'; -import reduceRightAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-reduce-right@esm/index.mjs'; +import reduceRightAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-reduce-right@v0.2.2-esm/index.mjs'; var files = [ resolve( __dirname, 'package.json' ), From 927667549f784c21f792788f08df4fc782a3c2e3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 28 Jul 2024 00:22:08 +0000 Subject: [PATCH 117/147] Auto-generated commit --- README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bea9a5a..a07bd10 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import reduceRightAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-reduce-right@esm/index.mjs'; +``` +The previous example will load the latest bundled code from the esm branch. Alternatively, you may load a specific version by loading the file from one of the [tagged bundles](https://github.com/stdlib-js/utils-async-reduce-right/tags). For example, + ```javascript import reduceRightAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-reduce-right@v0.2.2-esm/index.mjs'; ``` @@ -58,7 +63,7 @@ import reduceRightAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async- You can also import the following named exports from the package: ```javascript -import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-reduce-right@v0.2.2-esm/index.mjs'; +import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-reduce-right@esm/index.mjs'; ``` #### reduceRightAsync( collection, initial, \[options,] reducer, done ) @@ -381,7 +386,7 @@ The function accepts the same `options` as `reduceRightAsync()`. var resolve = require( 'path' ).resolve; import readFile from 'https://cdn.jsdelivr.net/gh/stdlib-js/fs-read-file@esm/index.mjs'; -import reduceRightAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-reduce-right@v0.2.2-esm/index.mjs'; +import reduceRightAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-reduce-right@esm/index.mjs'; var files = [ resolve( __dirname, 'package.json' ), From ce0af5ceda8b73aab161791b69a0a0d7e77da88c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 04:24:24 +0000 Subject: [PATCH 118/147] Transform error messages --- lib/factory.js | 8 ++++---- lib/validate.js | 8 ++++---- package.json | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 1125052..e107128 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -22,7 +22,7 @@ var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var PINF = require( '@stdlib/constants-float64-pinf' ); var validate = require( './validate.js' ); var limit = require( './limit.js' ); @@ -109,7 +109,7 @@ function factory( options, fcn ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '1RZ3q', f ) ); } if ( opts.series === void 0 && opts.limit === void 0 ) { opts.series = true; @@ -134,10 +134,10 @@ function factory( options, fcn ) { */ function reduceRightAsync( collection, initial, done ) { if ( !isCollection( collection ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a collection. Value: `%s`.', collection ) ); + throw new TypeError( format( '1RZAh', collection ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '1RZ3q', done ) ); } return limit( collection, initial, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index 9ba927e..0c666fe 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,7 +54,7 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '1RZ2V', options ) ); } if ( hasOwnProp( options, 'thisArg' ) ) { opts.thisArg = options.thisArg; @@ -62,13 +62,13 @@ function validate( opts, options ) { if ( hasOwnProp( options, 'series' ) ) { opts.series = options.series; if ( !isBoolean( opts.series ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'series', opts.series ) ); + return new TypeError( format( '1RZ2o', 'series', opts.series ) ); } } if ( hasOwnProp( options, 'limit' ) ) { opts.limit = options.limit; if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'limit', opts.limit ) ); + return new TypeError( format( '1RZ3P', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index acd1144..addc507 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-plain-object": "^0.2.2", "@stdlib/assert-is-positive-integer": "^0.2.2", "@stdlib/constants-float64-pinf": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.3.2", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", "debug": "^2.6.9", From f0159a2819f56fdc66b29648d1c50a7d762e5654 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 08:19:08 +0000 Subject: [PATCH 119/147] Remove files --- index.d.ts | 410 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5257 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index f6cba5d..0000000 --- a/index.d.ts +++ /dev/null @@ -1,410 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Execution context. - */ - thisArg?: ThisParameterType>; - - /** - * The maximum number of pending invocations at any one time. - */ - limit?: number; - - /** - * Boolean indicating whether to sequentially invoke the reducer function for each `collection` element. If `true`, the function sets `options.limit=1`. Default: true. - */ - series?: boolean; -} - -/** -* Callback function. -*/ -type Nullary = () => void; - -/** -* Callback function. -* -* @param error - encountered error or null -*/ -type Unary = ( error: Error | null ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Binary = ( error: Error | null, accumulator: U ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param next - a callback to be invoked after processing a collection `value` -*/ -type TernaryReducer = ( this: V, accumulator: U, value: T, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuaternaryReducer = ( this: V, accumulator: U, value: T, index: number, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuinaryReducer = ( this: V, accumulator: U, value: T, index: number, collection: Collection, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type Reducer = TernaryReducer | QuaternaryReducer | QuinaryReducer; - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result. -* -* @param collection - input collection -* @param initial - initial value -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( collection: Collection, initial: U, done: Callback ) => void; - -/** -* Interface for `reduceRightAsync`. -*/ -interface ReduceRightAsync { - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, {}, read, done ); - */ - ( collection: Collection, initial: U, options: Options, reducer: Reducer, done: Callback ): void; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, read, done ); - */ - ( collection: Collection, initial: U, reducer: Reducer, done: Callback ): void; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @throws must provide valid options - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var opts = { - * 'series': false - * }; - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( opts, read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( options: Options, reducer: Reducer ): FactoryFunction; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param reducer - function to invoke for each element in a collection - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( reducer: Reducer ): FactoryFunction; -} - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param collection - input collection -* @param initial - initial value -* @param options - function options -* @param options.thisArg - execution context -* @param options.limit - maximum number of pending invocations at any one time -* @param 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 (default: true) -* @param reducer - function to invoke for each element in a collection -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -declare var reduceRightAsync: ReduceRightAsync; - - -// EXPORTS // - -export = reduceRightAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 234a485..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as c}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";function m(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var d=m(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function f(e,m){var f,u,p;if(f={},arguments.length>1){if(u=function(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("1RZ2o","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!c(e.limit))?new TypeError(r("1RZ3P","limit",e.limit)):null):new TypeError(r("1RZ2V",t))}(f,e),u)throw u;p=m}else p=e;if(!t(p))throw new TypeError(r("1RZ3q",p));return void 0===f.series&&void 0===f.limit&&(f.series=!0),f.series?f.limit=1:f.limit||(f.limit=s),function(e,s,n){if(!i(e))throw new TypeError(r("1RZAh",e));if(!t(n))throw new TypeError(r("1RZ3q",n));return function(e,t,i,r,s){var n,o,l,c,m,f;if(c=e.length,d("Collection length: %d",c),0===c)return d("Finished processing a collection."),s(null,t);for(l=c0&&u();function u(){function s(e,i){if(!o){if(e)return o=!0,p(e);d("Accumulator: %s",JSON.stringify(i)),t=i,p()}}d("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function p(e){return e?(d("Encountered an error: %s",e.message),s(e)):(d("Processed %d of %d collection elements.",n+=1,c),m>0?u():n===c?(d("Finished processing a collection."),s(null,t)):void 0)}}(e,s,f,p,(function(e,t){if(e)return n(e);n(null,t)}))}}function u(e,t,i,r,s){if(arguments.length<5)return f(i)(e,t,r);f(i,r)(e,t,s)}e(u,"factory",f);export{u as default,f as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index e11f2cb..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/limit.js","../lib/factory.js","../lib/validate.js","../lib/main.js","../lib/index.js"],"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 logger = require( 'debug' );\n\n\n// VARIABLES //\n\nvar debug = logger( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RZ3q', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '1RZAh', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RZ3q', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '1RZ2V', 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( '1RZ2o', '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( '1RZ3P', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["debug","logger","factory","options","fcn","opts","err","f","arguments","length","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","validate","isFunction","PINF","collection","initial","done","isCollection","acc","count","flg","lim","len","idx","i","next","cb","error","result","clbk","JSON","stringify","call","message","reduceRightAsync","setReadOnly","main"],"mappings":";;81CA2BIA,uDAAQC,CAAQ,4BCoEpB,SAASC,EAASC,EAASC,GAC1B,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAA,EACFG,UAAUC,OAAS,EAAI,CAE3B,GADAH,EChDF,SAAmBD,EAAMF,GACxB,OAAMO,EAAUP,IAGXQ,EAAYR,EAAS,aACzBE,EAAKO,QAAUT,EAAQS,SAEnBD,EAAYR,EAAS,YACzBE,EAAKQ,OAASV,EAAQU,QAChBC,EAAWT,EAAKQ,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUX,EAAKQ,SAGnDF,EAAYR,EAAS,WACzBE,EAAKY,MAAQd,EAAQc,OACfC,EAAmBb,EAAKY,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASX,EAAKY,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASb,GAkBzC,CD4BQgB,CAAUd,EAAMF,GACjBG,EACJ,MAAMA,EAEPC,EAAIH,CACN,MACEG,EAAIJ,EAEL,IAAMiB,EAAYb,GACjB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAUvC,YARqB,IAAhBF,EAAKQ,aAAoC,IAAfR,EAAKY,QACnCZ,EAAKQ,QAAS,GAEVR,EAAKQ,OACTR,EAAKY,MAAQ,EACDZ,EAAKY,QACjBZ,EAAKY,MAAQI,GAed,SAA2BC,EAAYC,EAASC,GAC/C,IAAMC,EAAcH,GACnB,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,IAAMF,EAAYI,GACjB,MAAM,IAAIT,UAAWC,EAAQ,QAASQ,IAEvC,ODhGF,SAAgBF,EAAYI,EAAKrB,EAAMD,EAAKoB,GAC3C,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMR,EAAWb,OACjBT,EAAO,wBAAyB8B,GAEnB,IAARA,EAEJ,OADA9B,EAAO,qCACAwB,EAAM,KAAME,GAYpB,IATCG,EADIC,EAAMzB,EAAKY,MACTa,EAEAzB,EAAKY,MAEZjB,EAAO,wBAAyB6B,GAChC7B,EAAO,0BAA2BI,EAAIK,QAEtCkB,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVE,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKR,EAAL,CAIA,GAAKO,EAEJ,OADAP,GAAM,EACCS,EAAMF,GAEdnC,EAAO,kBAAmBsC,KAAKC,UAAWH,IAC1CV,EAAMU,EACNC,GAPC,CAQD,CA5BDrC,EAAO,6BADP+B,GAAO,EACmCO,KAAKC,UAAWjB,EAAYS,KAClD,IAAf3B,EAAIK,OACRL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOG,GACtB,IAAf9B,EAAIK,OACfL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKG,GAErD9B,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKT,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJnC,EAAO,2BAA4BmC,EAAMM,SAClCjB,EAAMW,KAGdnC,EAAO,0CADP2B,GAAS,EACgDG,GACpDC,EAAM,EACHE,IAEHN,IAAUG,GACd9B,EAAO,qCACAwB,EAAM,KAAME,SAFpB,EAIA,CACF,CCKST,CAAOK,EAAYC,EAASlB,EAAME,GAUzC,SAAe4B,EAAOT,GACrB,GAAKS,EACJ,OAAOX,EAAMW,GAEdX,EAAM,KAAME,EACZ,GACD,CACF,CE1EA,SAASgB,EAAkBpB,EAAYC,EAASpB,EAASC,EAAKoB,GAC7D,GAAKhB,UAAUC,OAAS,EACvB,OAAOP,EAASC,EAATD,CAAoBoB,EAAYC,EAASnB,GAEjDF,EAASC,EAASC,EAAlBF,CAAyBoB,EAAYC,EAASC,EAC/C,CClBAmB,EAAAC,EAAA,UAAA1C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 69bcdc8..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 8b4e1f6a0cd5645ffddea28cd98854e66eeea9a4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 08:19:20 +0000 Subject: [PATCH 120/147] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 158 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.factory.js | 73 - benchmark/benchmark.js | 160 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 224 - docs/types/test.ts | 166 - examples/index.js | 55 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 164 - lib/index.js | 77 - lib/limit.js | 142 - lib/main.js | 95 - lib/validate.js | 80 - package.json | 65 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 1095 ----- test/test.js | 38 - test/test.main.js | 1035 ----- test/test.validate.js | 181 - 50 files changed, 4873 insertions(+), 7124 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/limit.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index a85e7a0..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-08-01T03:09:22.740Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1e08946..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 5358060..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index fa37f2d..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '37 1 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -460,7 +457,7 @@ reduceRightAsync( files, acc, read, done ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -531,11 +528,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right +[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right/tree/esm -[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce +[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index b155fd2..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var reduceRightAsync; - var arr; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - reduceRightAsync = factory( onItem ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - var acc; - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index af5c346..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var reduceRightAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=false', function benchmark( b ) { - var opts; - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'series': false - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var arr; - var len; - var acc; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'limit': 3 - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b8adcd2..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right" -%% click B href "https://github.com/stdlib-js/utils-async-reduce-right/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-reduce-right/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-reduce-right/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-reduce-right/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right -[production-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-async-reduce-right/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-async-reduce-right/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-async-reduce-right/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 47a072e..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import reduceRightAsync from '../docs/types/index'; -export = reduceRightAsync; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 530ca4d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var c=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var x=c(function(U,O){ -var R=require('@stdlib/assert-is-plain-object/dist'),h=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,k=require('@stdlib/assert-is-positive-integer/dist').isPrimitive,d=require('@stdlib/error-tools-fmtprodmsg/dist');function I(e,r){return R(r)?(h(r,"thisArg")&&(e.thisArg=r.thisArg),h(r,"series")&&(e.series=r.series,!j(e.series))?new TypeError(d('1RZ2o',"series",e.series)):h(r,"limit")&&(e.limit=r.limit,!k(e.limit))?new TypeError(d('1RZ3P',"limit",e.limit)):null):new TypeError(d('1RZ2V',r));}O.exports=I -});var P=c(function(W,E){ -var J=require("debug"),a=J("reduce-right-async:limit");function L(e,r,i,t,s){var f,m,v,n,u,g;if(n=e.length,a("Collection length: %d",n),n===0)return a("Finished processing a collection."),s(null,r);for(n0&&o();function o(){u-=1,a("Collection element %d: %s.",u,JSON.stringify(e[u])),t.length===3?t.call(i.thisArg,r,e[u],l):t.length===4?t.call(i.thisArg,r,e[u],u,l):t.call(i.thisArg,r,e[u],u,e,l);function l(w,A){if(!m){if(w)return m=!0,b(w);a("Accumulator: %s",JSON.stringify(A)),r=A,b()}}}function b(l){if(l)return a("Encountered an error: %s",l.message),s(l);if(f+=1,a("Processed %d of %d collection elements.",f,n),u>0)return o();if(f===n)return a("Finished processing a collection."),s(null,r)}}E.exports=L -});var q=c(function(X,F){ -var T=require('@stdlib/assert-is-function/dist'),S=require('@stdlib/assert-is-collection/dist'),y=require('@stdlib/error-tools-fmtprodmsg/dist'),B=require('@stdlib/constants-float64-pinf/dist'),z=x(),D=P();function G(e,r){var i,t,s;if(i={},arguments.length>1){if(t=z(i,e),t)throw t;s=r}else s=e;if(!T(s))throw new TypeError(y('1RZ3q',s));return i.series===void 0&&i.limit===void 0&&(i.series=!0),i.series?i.limit=1:i.limit||(i.limit=B),f;function f(m,v,n){if(!S(m))throw new TypeError(y('1RZAh',m));if(!T(n))throw new TypeError(y('1RZ3q',n));return D(m,v,i,s,u);function u(g,o){if(g)return n(g);n(null,o)}}}F.exports=G -});var N=c(function(Y,C){ -var p=q();function H(e,r,i,t,s){if(arguments.length<5)return p(i)(e,r,t);p(i,t)(e,r,s)}C.exports=H -});var K=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),V=N(),M=q();K(V,"factory",M);module.exports=V; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index acb9d67..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/limit.js", "../lib/factory.js", "../lib/main.js", "../lib/index.js"], - "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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\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 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 to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\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 === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, 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 ( !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, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\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* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nmodule.exports = reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' );\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, 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"], - "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,0BAA2B,EAkB/C,SAASE,EAAOC,EAAYC,EAAKC,EAAMC,EAAKC,EAAO,CAClD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMR,EAAW,OACjBF,EAAO,wBAAyBU,CAAI,EAE/BA,IAAQ,EACZ,OAAAV,EAAO,mCAAoC,EACpCM,EAAM,KAAMH,CAAI,EAYxB,IAVKO,EAAMN,EAAK,MACfK,EAAMC,EAEND,EAAML,EAAK,MAEZJ,EAAO,wBAAyBS,CAAI,EACpCT,EAAO,0BAA2BK,EAAI,MAAO,EAE7CE,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVE,EAAK,EAQP,SAASA,GAAO,CACfF,GAAO,EACPX,EAAO,6BAA8BW,EAAK,KAAK,UAAWT,EAAYS,CAAI,CAAE,CAAE,EACzEN,EAAI,SAAW,EACnBA,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGG,CAAG,EACxCT,EAAI,SAAW,EAC1BA,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGA,EAAKG,CAAG,EAExDT,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGA,EAAKT,EAAYY,CAAG,EAUrE,SAASA,EAAIC,EAAOC,EAAS,CAC5B,GAAK,CAAAR,EAIL,IAAKO,EACJ,OAAAP,EAAM,GACCS,EAAMF,CAAM,EAEpBf,EAAO,kBAAmB,KAAK,UAAWgB,CAAO,CAAE,EACnDb,EAAMa,EACNC,EAAK,EACN,CACD,CASA,SAASA,EAAMF,EAAQ,CACtB,GAAKA,EACJ,OAAAf,EAAO,2BAA4Be,EAAM,OAAQ,EAC1CT,EAAMS,CAAM,EAIpB,GAFAR,GAAS,EACTP,EAAO,0CAA2CO,EAAOG,CAAI,EACxDC,EAAM,EACV,OAAOE,EAAK,EAEb,GAAKN,IAAUG,EACd,OAAAV,EAAO,mCAAoC,EACpCM,EAAM,KAAMH,CAAI,CAEzB,CACD,CAKAL,EAAO,QAAUG,IC7IjB,IAAAiB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,gCAAiC,EACjDC,EAAW,IACXC,EAAQ,IAoEZ,SAASC,EAASC,EAASC,EAAM,CAChC,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,CAACP,EAAYW,CAAE,EACnB,MAAM,IAAI,UAAWT,EAAQ,mEAAoES,CAAE,CAAE,EAEtG,OAAKF,EAAK,SAAW,QAAUA,EAAK,QAAU,SAC7CA,EAAK,OAAS,IAEVA,EAAK,OACTA,EAAK,MAAQ,EACDA,EAAK,QACjBA,EAAK,MAAQN,GAEPS,EAaP,SAASA,EAAkBC,EAAYC,EAASC,EAAO,CACtD,GAAK,CAACd,EAAcY,CAAW,EAC9B,MAAM,IAAI,UAAWX,EAAQ,sEAAuEW,CAAW,CAAE,EAElH,GAAK,CAACb,EAAYe,CAAK,EACtB,MAAM,IAAI,UAAWb,EAAQ,mEAAoEa,CAAK,CAAE,EAEzG,OAAOV,EAAOQ,EAAYC,EAASL,EAAME,EAAGK,CAAK,EAUjD,SAASA,EAAMC,EAAOC,EAAM,CAC3B,GAAKD,EACJ,OAAOF,EAAME,CAAM,EAEpBF,EAAM,KAAMG,CAAI,CACjB,CACD,CACD,CAKAnB,EAAO,QAAUO,ICnKjB,IAAAa,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,IA8Dd,SAASC,EAAkBC,EAAYC,EAASC,EAASC,EAAKC,EAAO,CACpE,GAAK,UAAU,OAAS,EACvB,OAAON,EAASI,CAAQ,EAAGF,EAAYC,EAASE,CAAI,EAErDL,EAASI,EAASC,CAAI,EAAGH,EAAYC,EAASG,CAAK,CACpD,CAKAP,EAAO,QAAUE,IC9BjB,IAAIM,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "isPositiveInteger", "format", "validate", "opts", "options", "require_limit", "__commonJSMin", "exports", "module", "logger", "debug", "limit", "collection", "acc", "opts", "fcn", "done", "count", "flg", "lim", "len", "idx", "i", "next", "cb", "error", "result", "clbk", "require_factory", "__commonJSMin", "exports", "module", "isFunction", "isCollection", "format", "PINF", "validate", "limit", "factory", "options", "fcn", "opts", "err", "f", "reduceRightAsync", "collection", "initial", "done", "clbk", "error", "acc", "require_main", "__commonJSMin", "exports", "module", "factory", "reduceRightAsync", "collection", "initial", "options", "fcn", "done", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3f22669..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,224 +0,0 @@ - -{{alias}}( collection, initial, [options,] reducer, done ) - Applies a function against an accumulator and each element in a collection - and returns the accumulated result, iterating from right to left. - - When invoked, `reducer` is provided a maximum of five arguments: - - - `accumulator`: accumulated value - - `value`: collection value - - `index`: collection index - - `collection`: the input collection - - `next`: a callback to be invoked after processing a collection `value` - - The actual number of provided arguments depends on function length. If - `reducer` accepts three arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `next` - - If `reducer` accepts four arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `index` - - `next` - - For every other `reducer` signature, `reducer` is provided all five - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `accumulator`: accumulated value - - If a provided function calls the `next` callback with a truthy `error` - argument, the function suspends execution and immediately calls the `done` - callback for subsequent `error` handling. - - Execution is *not* guaranteed to be asynchronous. To guarantee asynchrony, - 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`). - - The function does not support dynamic collection resizing. - - If provided an empty collection, the function invokes the `done` callback - with the `initial` value as the second argument. - - The function does not skip `undefined` elements. - - When processing collection elements concurrently, *beware* of race - conditions when updating an accumulator. This is especially true when an - accumulator is a primitive (e.g., a number). In general, prefer object - accumulators. - - Parameters - ---------- - collection: Array|TypedArray|Object - Input collection over which to iterate. If provided an object, the - object must be array-like (excluding strings and functions). - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - reducer: Function - The function to invoke for each element in a collection. - - done: Function - A callback invoked either upon processing all collection elements or - upon encountering an error. - - Examples - -------- - // Basic usage: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, fcn, done ) - 3000 - 2500 - 1000 - 6500 - - // Limit number of concurrent invocations: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'limit': 2 }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 2500 - 3000 - 1000 - 6500 - - // Process concurrently: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'series': false }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 1000 - 2500 - 3000 - 6500 - - -{{alias}}.factory( [options,] fcn ) - Returns a function which applies a function against an accumulator and each - element in a collection and returns the accumulated result, iterating from - right to left. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - fcn: Function - The function to invoke for each element in a collection. - - Returns - ------- - out: Function - A function which invokes a function for each element in a collection. - - Examples - -------- - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > var opts = { 'series': false }; - > var f = {{alias}}.factory( opts, fcn ); - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > f( arr, acc, done ) - 1000 - 2500 - 3000 - 6500 - > acc = { 'sum': 0 }; - > arr = [ 1000, 1500, 2000 ]; - > f( arr, acc, done ) - 1000 - 1500 - 2000 - 4500 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0455864..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,166 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unsafe-assignment */ - -import reduceRightAsync = require( './index' ); - -const reducer = ( acc: any, value: number, index: number, next: Function ) => { - acc.sum += value; - if ( index === void 0 ) { - throw new Error( '`index` is missing.' ); - } - next( null, acc ); -}; - -const done = ( error: Error | null, acc: any ) => { - if ( error ) { - throw error; - } - if ( acc === void 0 ) { - throw new Error( '`acc` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( 2, acc, reducer, done ); // $ExpectError - reduceRightAsync( false, acc, reducer, done ); // $ExpectError - reduceRightAsync( true, acc, reducer, done ); // $ExpectError - reduceRightAsync( {}, acc, reducer, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a predicate argument which is not a predicate function... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 2, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, false, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, true, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 'abc', done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, [], done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a done callback argument which is not a function having a supported signature... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 2 ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, false ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, true ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 'abc' ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, {} ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, [] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const acc = { 'sum': 0 }; - reduceRightAsync(); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, reducer, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - reduceRightAsync.factory( reducer ); // $ExpectType FactoryFunction - reduceRightAsync.factory( { 'series': true }, reducer ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - reduceRightAsync.factory( [], reducer ); // $ExpectError - reduceRightAsync.factory( 123, reducer ); // $ExpectError - reduceRightAsync.factory( 'abc', reducer ); // $ExpectError - reduceRightAsync.factory( false, reducer ); // $ExpectError - reduceRightAsync.factory( true, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not a predicate function... -{ - reduceRightAsync.factory( {} ); // $ExpectError - reduceRightAsync.factory( true ); // $ExpectError - reduceRightAsync.factory( false ); // $ExpectError - reduceRightAsync.factory( {}, 123 ); // $ExpectError - reduceRightAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1( 12, acc, done ); // $ExpectError - fcn1( true, acc, done ); // $ExpectError - fcn1( false, acc, done ); // $ExpectError - fcn1( {}, acc, done ); // $ExpectError - - fcn1( [ 3000, 2500, 1000 ], acc, 12 ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, true ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, false ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, '5' ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, {} ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, [] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1(); // $ExpectError - fcn1( [ 3000, 2500, 1000 ] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - reduceRightAsync.factory( { 'limit': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': true }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': false }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - reduceRightAsync.factory( { 'series': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': 12 }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - reduceRightAsync.factory(); // $ExpectError - reduceRightAsync.factory( {}, reducer, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index dd64345..0000000 --- a/examples/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var resolve = require( 'path' ).resolve; -var readFile = require( '@stdlib/fs-read-file' ); -var reduceRightAsync = require( './../lib' ); - -var files = [ - resolve( __dirname, '..', 'package.json' ), - resolve( __dirname, '..', 'README.md' ) -]; - -function done( error, acc ) { - if ( error ) { - throw error; - } - console.log( acc.count ); -} - -function read( acc, file, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( file, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( null, acc ); - } - acc.count += 1; - next( null, acc ); - } -} - -var acc = { - 'count': 0 -}; -reduceRightAsync( files, acc, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 28e0a36..f6cba5d 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..234a485 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as c}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";function m(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var d=m(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function f(e,m){var f,u,p;if(f={},arguments.length>1){if(u=function(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("1RZ2o","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!c(e.limit))?new TypeError(r("1RZ3P","limit",e.limit)):null):new TypeError(r("1RZ2V",t))}(f,e),u)throw u;p=m}else p=e;if(!t(p))throw new TypeError(r("1RZ3q",p));return void 0===f.series&&void 0===f.limit&&(f.series=!0),f.series?f.limit=1:f.limit||(f.limit=s),function(e,s,n){if(!i(e))throw new TypeError(r("1RZAh",e));if(!t(n))throw new TypeError(r("1RZ3q",n));return function(e,t,i,r,s){var n,o,l,c,m,f;if(c=e.length,d("Collection length: %d",c),0===c)return d("Finished processing a collection."),s(null,t);for(l=c0&&u();function u(){function s(e,i){if(!o){if(e)return o=!0,p(e);d("Accumulator: %s",JSON.stringify(i)),t=i,p()}}d("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function p(e){return e?(d("Encountered an error: %s",e.message),s(e)):(d("Processed %d of %d collection elements.",n+=1,c),m>0?u():n===c?(d("Finished processing a collection."),s(null,t)):void 0)}}(e,s,f,p,(function(e,t){if(e)return n(e);n(null,t)}))}}function u(e,t,i,r,s){if(arguments.length<5)return f(i)(e,t,r);f(i,r)(e,t,s)}e(u,"factory",f);export{u as default,f as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..e11f2cb --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/limit.js","../lib/factory.js","../lib/validate.js","../lib/main.js","../lib/index.js"],"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 logger = require( 'debug' );\n\n\n// VARIABLES //\n\nvar debug = logger( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RZ3q', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '1RZAh', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RZ3q', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '1RZ2V', 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( '1RZ2o', '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( '1RZ3P', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["debug","logger","factory","options","fcn","opts","err","f","arguments","length","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","validate","isFunction","PINF","collection","initial","done","isCollection","acc","count","flg","lim","len","idx","i","next","cb","error","result","clbk","JSON","stringify","call","message","reduceRightAsync","setReadOnly","main"],"mappings":";;81CA2BIA,uDAAQC,CAAQ,4BCoEpB,SAASC,EAASC,EAASC,GAC1B,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAA,EACFG,UAAUC,OAAS,EAAI,CAE3B,GADAH,EChDF,SAAmBD,EAAMF,GACxB,OAAMO,EAAUP,IAGXQ,EAAYR,EAAS,aACzBE,EAAKO,QAAUT,EAAQS,SAEnBD,EAAYR,EAAS,YACzBE,EAAKQ,OAASV,EAAQU,QAChBC,EAAWT,EAAKQ,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUX,EAAKQ,SAGnDF,EAAYR,EAAS,WACzBE,EAAKY,MAAQd,EAAQc,OACfC,EAAmBb,EAAKY,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASX,EAAKY,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASb,GAkBzC,CD4BQgB,CAAUd,EAAMF,GACjBG,EACJ,MAAMA,EAEPC,EAAIH,CACN,MACEG,EAAIJ,EAEL,IAAMiB,EAAYb,GACjB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAUvC,YARqB,IAAhBF,EAAKQ,aAAoC,IAAfR,EAAKY,QACnCZ,EAAKQ,QAAS,GAEVR,EAAKQ,OACTR,EAAKY,MAAQ,EACDZ,EAAKY,QACjBZ,EAAKY,MAAQI,GAed,SAA2BC,EAAYC,EAASC,GAC/C,IAAMC,EAAcH,GACnB,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,IAAMF,EAAYI,GACjB,MAAM,IAAIT,UAAWC,EAAQ,QAASQ,IAEvC,ODhGF,SAAgBF,EAAYI,EAAKrB,EAAMD,EAAKoB,GAC3C,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMR,EAAWb,OACjBT,EAAO,wBAAyB8B,GAEnB,IAARA,EAEJ,OADA9B,EAAO,qCACAwB,EAAM,KAAME,GAYpB,IATCG,EADIC,EAAMzB,EAAKY,MACTa,EAEAzB,EAAKY,MAEZjB,EAAO,wBAAyB6B,GAChC7B,EAAO,0BAA2BI,EAAIK,QAEtCkB,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVE,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKR,EAAL,CAIA,GAAKO,EAEJ,OADAP,GAAM,EACCS,EAAMF,GAEdnC,EAAO,kBAAmBsC,KAAKC,UAAWH,IAC1CV,EAAMU,EACNC,GAPC,CAQD,CA5BDrC,EAAO,6BADP+B,GAAO,EACmCO,KAAKC,UAAWjB,EAAYS,KAClD,IAAf3B,EAAIK,OACRL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOG,GACtB,IAAf9B,EAAIK,OACfL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKG,GAErD9B,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKT,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJnC,EAAO,2BAA4BmC,EAAMM,SAClCjB,EAAMW,KAGdnC,EAAO,0CADP2B,GAAS,EACgDG,GACpDC,EAAM,EACHE,IAEHN,IAAUG,GACd9B,EAAO,qCACAwB,EAAM,KAAME,SAFpB,EAIA,CACF,CCKST,CAAOK,EAAYC,EAASlB,EAAME,GAUzC,SAAe4B,EAAOT,GACrB,GAAKS,EACJ,OAAOX,EAAMW,GAEdX,EAAM,KAAME,EACZ,GACD,CACF,CE1EA,SAASgB,EAAkBpB,EAAYC,EAASpB,EAASC,EAAKoB,GAC7D,GAAKhB,UAAUC,OAAS,EACvB,OAAOP,EAASC,EAATD,CAAoBoB,EAAYC,EAASnB,GAEjDF,EAASC,EAASC,EAAlBF,CAAyBoB,EAAYC,EAASC,EAC/C,CClBAmB,EAAAC,EAAA,UAAA1C"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index e107128..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,164 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var validate = require( './validate.js' ); -var limit = require( './limit.js' ); - - -// MAIN // - -/** -* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} last argument must be a function -* @returns {Function} function which invokes the provided function once for each element in a collection -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error, data ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var opts = { -* 'series': false -* }; -* -* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: -* var reduceRightAsync = factory( opts, read ); -* -* // Create a collection over which to iterate: -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* // Define a callback which handles errors: -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* // Run `read` for each element in `files`: -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, done ); -*/ -function factory( options, fcn ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = fcn; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '1RZ3q', f ) ); - } - if ( opts.series === void 0 && opts.limit === void 0 ) { - opts.series = true; - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return reduceRightAsync; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * @private - * @param {Collection} collection - input collection - * @param {*} initial - initial value - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be a collection - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function reduceRightAsync( collection, initial, done ) { - if ( !isCollection( collection ) ) { - throw new TypeError( format( '1RZAh', collection ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '1RZ3q', done ) ); - } - return limit( collection, initial, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {*} [acc] - accumulated value - * @returns {void} - */ - function clbk( error, acc ) { - if ( error ) { - return done( error ); - } - done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ae657ff..0000000 --- a/lib/index.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* @module @stdlib/utils-async-reduce-right -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' ); -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/limit.js b/lib/limit.js deleted file mode 100644 index cdb60af..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); - - -// VARIABLES // - -var debug = logger( 'reduce-right-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each element in a collection, limiting the number of concurrently pending functions and iterating from right to left. -* -* @private -* @param {Collection} collection - input collection -* @param {*} acc - initial value -* @param {Options} opts - function options -* @param {*} [opts.thisArg] - execution context -* @param {PositiveInteger} [opts.limit] - maximum number of pending function invocations -* @param {Function} fcn - function to invoke -* @param {Callback} done - function to invoke upon completion or upon encountering an error -* @returns {void} -*/ -function limit( collection, acc, opts, fcn, done ) { - var count; - var flg; - var lim; - var len; - var idx; - var i; - - len = collection.length; - debug( 'Collection length: %d', len ); - - if ( len === 0 ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - count = 0; - idx = len; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all collection elements... - if ( idx > 0 ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next element in a collection. - * - * @private - */ - function next() { - idx -= 1; - debug( 'Collection element %d: %s.', idx, JSON.stringify( collection[ idx ] ) ); - if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], cb ); - } else if ( fcn.length === 4 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, cb ); - } else { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len - } - /** - * Callback invoked once a provided function finishes processing a collection element. - * - * @private - * @param {*} [error] - error - * @param {*} [result] - accumulation result - * @returns {void} - */ - function cb( error, result ) { - if ( flg ) { - // Prevent further processing of collection elements: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Accumulator: %s', JSON.stringify( result ) ); - acc = result; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next collection element. - * - * @private - * @param {*} [error] - error - * @returns {void} - */ - function clbk( error ) { - if ( error ) { - debug( 'Encountered an error: %s', error.message ); - return done( error ); - } - count += 1; - debug( 'Processed %d of %d collection elements.', count, len ); - if ( idx > 0 ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index c8b0d0f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param {Collection} collection - input collection -* @param {*} initial - initial value -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} second-to-last argument must be a function -* @throws {TypeError} last argument must be a function -* @returns {void} -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -function reduceRightAsync( collection, initial, options, fcn, done ) { - if ( arguments.length < 5 ) { - return factory( options )( collection, initial, fcn ); - } - factory( options, fcn )( collection, initial, done ); -} - - -// EXPORTS // - -module.exports = reduceRightAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 0c666fe..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @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 -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'thisArg': {}, -* 'series': false, -* 'limit': 10 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '1RZ2V', options ) ); - } - if ( hasOwnProp( options, 'thisArg' ) ) { - opts.thisArg = options.thisArg; - } - if ( hasOwnProp( options, 'series' ) ) { - opts.series = options.series; - if ( !isBoolean( opts.series ) ) { - return new TypeError( format( '1RZ2o', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '1RZ3P', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index addc507..563c57c 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,44 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-collection": "^0.2.2", - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/assert-is-positive-integer": "^0.2.2", - "@stdlib/constants-float64-pinf": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "debug": "^2.6.9", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/constants-float64-eps": "^0.2.2", - "@stdlib/fs-read-file": "^0.2.2", - "@stdlib/utils-noop": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..69bcdc8 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 8244931..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1095 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( {}, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, next ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - factory( opts, next ); - }; - } -}); - -tape( 'the function returns a function (no options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided a collection (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a collection (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (1 argument)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (2 arguments)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with five arguments', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn() { - var value; - var next; - var acc; - var k; - - acc = arguments[ 0 ]; - value = arguments[ 1 ]; - k = arguments[ 2 ]; - next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( k, i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the returned function supports processing collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements concurrently', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 100, 250, 300 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements sequentially (limit = 1)', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of collection elements which are processed at any one time', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 250, 300, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 250, 100, 300 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var reduceRightAsync; - var arr; - - reduceRightAsync = factory( fcn ); - arr = []; - - reduceRightAsync( arr, 0, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var reduceRightAsync; - var obj; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = []; - obj = {}; - reduceRightAsync( arr, obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - i = 0; - - reduceRightAsync( arr, {}, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, acc ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the returned function does not skip empty elements', function test( t ) { - var reduceRightAsync; - var expected; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index f273a40..0000000 --- a/test/test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof reduceRightAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 1893240..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1035 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a collection', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (no options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, next, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, 0 ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - reduceRightAsync( [ 1, 2, 3 ], 0, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (1 argument)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (2 arguments)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with five arguments', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn() { - var next; - var acc; - var v; - - next = arguments[ 4 ]; - acc = arguments[ 0 ]; - v = arguments[ 1 ]; - - i -= 1; - j += 1; - - t.strictEqual( v, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, v ); - - function onTimeout() { - acc.sum += v; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'by default, the function processes collection elements sequentially', function test( t ) { - var values; - var count; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements concurrently', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 100, 250, 300 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': true - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially (limit = 1)', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var arr; - var ctx; - - arr = [ 3, 2, 1 ]; - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 3, 2, 1 ]; - opts = { - 'series': true - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 250, 100, 300 ]; - opts = { - 'limit': 2 - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var arr = []; - reduceRightAsync( arr, 0, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var arr = []; - var obj = {}; - - reduceRightAsync( arr, obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - arr = [ 3, 2, 1 ]; - i = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, value ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the function does not skip empty elements', function test( t ) { - var expected; - var arr; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, fcn, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 7660838..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,181 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `limit` option which is not a positive integer', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - -5, - 0, - 3.14, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'limit': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `series` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'series': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function accepts any value for the `thisArg` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'thisArg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err, null, 'returns null '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'thisArg': {}, - 'series': false, - 'limit': 10 - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From c38e397769a0ecab0dd19503d84ac171e450308f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 3 Aug 2024 19:12:59 +0000 Subject: [PATCH 121/147] Transform error messages --- lib/factory.js | 8 ++++---- lib/validate.js | 8 ++++---- package.json | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 1125052..e107128 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -22,7 +22,7 @@ var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var PINF = require( '@stdlib/constants-float64-pinf' ); var validate = require( './validate.js' ); var limit = require( './limit.js' ); @@ -109,7 +109,7 @@ function factory( options, fcn ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '1RZ3q', f ) ); } if ( opts.series === void 0 && opts.limit === void 0 ) { opts.series = true; @@ -134,10 +134,10 @@ function factory( options, fcn ) { */ function reduceRightAsync( collection, initial, done ) { if ( !isCollection( collection ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a collection. Value: `%s`.', collection ) ); + throw new TypeError( format( '1RZAh', collection ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '1RZ3q', done ) ); } return limit( collection, initial, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index 9ba927e..0c666fe 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,7 +54,7 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '1RZ2V', options ) ); } if ( hasOwnProp( options, 'thisArg' ) ) { opts.thisArg = options.thisArg; @@ -62,13 +62,13 @@ function validate( opts, options ) { if ( hasOwnProp( options, 'series' ) ) { opts.series = options.series; if ( !isBoolean( opts.series ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'series', opts.series ) ); + return new TypeError( format( '1RZ2o', 'series', opts.series ) ); } } if ( hasOwnProp( options, 'limit' ) ) { opts.limit = options.limit; if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'limit', opts.limit ) ); + return new TypeError( format( '1RZ3P', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index acd1144..addc507 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-plain-object": "^0.2.2", "@stdlib/assert-is-positive-integer": "^0.2.2", "@stdlib/constants-float64-pinf": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.3.2", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", "debug": "^2.6.9", From 6703db17ed09b3155be64327184aaf4b16ee013d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 3 Aug 2024 22:16:34 +0000 Subject: [PATCH 122/147] Remove files --- index.d.ts | 410 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5257 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index f6cba5d..0000000 --- a/index.d.ts +++ /dev/null @@ -1,410 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Execution context. - */ - thisArg?: ThisParameterType>; - - /** - * The maximum number of pending invocations at any one time. - */ - limit?: number; - - /** - * Boolean indicating whether to sequentially invoke the reducer function for each `collection` element. If `true`, the function sets `options.limit=1`. Default: true. - */ - series?: boolean; -} - -/** -* Callback function. -*/ -type Nullary = () => void; - -/** -* Callback function. -* -* @param error - encountered error or null -*/ -type Unary = ( error: Error | null ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Binary = ( error: Error | null, accumulator: U ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param next - a callback to be invoked after processing a collection `value` -*/ -type TernaryReducer = ( this: V, accumulator: U, value: T, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuaternaryReducer = ( this: V, accumulator: U, value: T, index: number, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuinaryReducer = ( this: V, accumulator: U, value: T, index: number, collection: Collection, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type Reducer = TernaryReducer | QuaternaryReducer | QuinaryReducer; - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result. -* -* @param collection - input collection -* @param initial - initial value -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( collection: Collection, initial: U, done: Callback ) => void; - -/** -* Interface for `reduceRightAsync`. -*/ -interface ReduceRightAsync { - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, {}, read, done ); - */ - ( collection: Collection, initial: U, options: Options, reducer: Reducer, done: Callback ): void; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, read, done ); - */ - ( collection: Collection, initial: U, reducer: Reducer, done: Callback ): void; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @throws must provide valid options - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var opts = { - * 'series': false - * }; - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( opts, read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( options: Options, reducer: Reducer ): FactoryFunction; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param reducer - function to invoke for each element in a collection - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( reducer: Reducer ): FactoryFunction; -} - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param collection - input collection -* @param initial - initial value -* @param options - function options -* @param options.thisArg - execution context -* @param options.limit - maximum number of pending invocations at any one time -* @param 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 (default: true) -* @param reducer - function to invoke for each element in a collection -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -declare var reduceRightAsync: ReduceRightAsync; - - -// EXPORTS // - -export = reduceRightAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 234a485..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as c}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";function m(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var d=m(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function f(e,m){var f,u,p;if(f={},arguments.length>1){if(u=function(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("1RZ2o","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!c(e.limit))?new TypeError(r("1RZ3P","limit",e.limit)):null):new TypeError(r("1RZ2V",t))}(f,e),u)throw u;p=m}else p=e;if(!t(p))throw new TypeError(r("1RZ3q",p));return void 0===f.series&&void 0===f.limit&&(f.series=!0),f.series?f.limit=1:f.limit||(f.limit=s),function(e,s,n){if(!i(e))throw new TypeError(r("1RZAh",e));if(!t(n))throw new TypeError(r("1RZ3q",n));return function(e,t,i,r,s){var n,o,l,c,m,f;if(c=e.length,d("Collection length: %d",c),0===c)return d("Finished processing a collection."),s(null,t);for(l=c0&&u();function u(){function s(e,i){if(!o){if(e)return o=!0,p(e);d("Accumulator: %s",JSON.stringify(i)),t=i,p()}}d("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function p(e){return e?(d("Encountered an error: %s",e.message),s(e)):(d("Processed %d of %d collection elements.",n+=1,c),m>0?u():n===c?(d("Finished processing a collection."),s(null,t)):void 0)}}(e,s,f,p,(function(e,t){if(e)return n(e);n(null,t)}))}}function u(e,t,i,r,s){if(arguments.length<5)return f(i)(e,t,r);f(i,r)(e,t,s)}e(u,"factory",f);export{u as default,f as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index e11f2cb..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/limit.js","../lib/factory.js","../lib/validate.js","../lib/main.js","../lib/index.js"],"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 logger = require( 'debug' );\n\n\n// VARIABLES //\n\nvar debug = logger( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RZ3q', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '1RZAh', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RZ3q', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '1RZ2V', 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( '1RZ2o', '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( '1RZ3P', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["debug","logger","factory","options","fcn","opts","err","f","arguments","length","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","validate","isFunction","PINF","collection","initial","done","isCollection","acc","count","flg","lim","len","idx","i","next","cb","error","result","clbk","JSON","stringify","call","message","reduceRightAsync","setReadOnly","main"],"mappings":";;81CA2BIA,uDAAQC,CAAQ,4BCoEpB,SAASC,EAASC,EAASC,GAC1B,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAA,EACFG,UAAUC,OAAS,EAAI,CAE3B,GADAH,EChDF,SAAmBD,EAAMF,GACxB,OAAMO,EAAUP,IAGXQ,EAAYR,EAAS,aACzBE,EAAKO,QAAUT,EAAQS,SAEnBD,EAAYR,EAAS,YACzBE,EAAKQ,OAASV,EAAQU,QAChBC,EAAWT,EAAKQ,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUX,EAAKQ,SAGnDF,EAAYR,EAAS,WACzBE,EAAKY,MAAQd,EAAQc,OACfC,EAAmBb,EAAKY,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASX,EAAKY,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASb,GAkBzC,CD4BQgB,CAAUd,EAAMF,GACjBG,EACJ,MAAMA,EAEPC,EAAIH,CACN,MACEG,EAAIJ,EAEL,IAAMiB,EAAYb,GACjB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAUvC,YARqB,IAAhBF,EAAKQ,aAAoC,IAAfR,EAAKY,QACnCZ,EAAKQ,QAAS,GAEVR,EAAKQ,OACTR,EAAKY,MAAQ,EACDZ,EAAKY,QACjBZ,EAAKY,MAAQI,GAed,SAA2BC,EAAYC,EAASC,GAC/C,IAAMC,EAAcH,GACnB,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,IAAMF,EAAYI,GACjB,MAAM,IAAIT,UAAWC,EAAQ,QAASQ,IAEvC,ODhGF,SAAgBF,EAAYI,EAAKrB,EAAMD,EAAKoB,GAC3C,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMR,EAAWb,OACjBT,EAAO,wBAAyB8B,GAEnB,IAARA,EAEJ,OADA9B,EAAO,qCACAwB,EAAM,KAAME,GAYpB,IATCG,EADIC,EAAMzB,EAAKY,MACTa,EAEAzB,EAAKY,MAEZjB,EAAO,wBAAyB6B,GAChC7B,EAAO,0BAA2BI,EAAIK,QAEtCkB,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVE,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKR,EAAL,CAIA,GAAKO,EAEJ,OADAP,GAAM,EACCS,EAAMF,GAEdnC,EAAO,kBAAmBsC,KAAKC,UAAWH,IAC1CV,EAAMU,EACNC,GAPC,CAQD,CA5BDrC,EAAO,6BADP+B,GAAO,EACmCO,KAAKC,UAAWjB,EAAYS,KAClD,IAAf3B,EAAIK,OACRL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOG,GACtB,IAAf9B,EAAIK,OACfL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKG,GAErD9B,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKT,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJnC,EAAO,2BAA4BmC,EAAMM,SAClCjB,EAAMW,KAGdnC,EAAO,0CADP2B,GAAS,EACgDG,GACpDC,EAAM,EACHE,IAEHN,IAAUG,GACd9B,EAAO,qCACAwB,EAAM,KAAME,SAFpB,EAIA,CACF,CCKST,CAAOK,EAAYC,EAASlB,EAAME,GAUzC,SAAe4B,EAAOT,GACrB,GAAKS,EACJ,OAAOX,EAAMW,GAEdX,EAAM,KAAME,EACZ,GACD,CACF,CE1EA,SAASgB,EAAkBpB,EAAYC,EAASpB,EAASC,EAAKoB,GAC7D,GAAKhB,UAAUC,OAAS,EACvB,OAAOP,EAASC,EAATD,CAAoBoB,EAAYC,EAASnB,GAEjDF,EAASC,EAASC,EAAlBF,CAAyBoB,EAAYC,EAASC,EAC/C,CClBAmB,EAAAC,EAAA,UAAA1C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 69bcdc8..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 68565f6dd2dab0cc19b7dcf647a2d7b4d2903d60 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 3 Aug 2024 22:16:55 +0000 Subject: [PATCH 123/147] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 212 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.factory.js | 73 - benchmark/benchmark.js | 160 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 224 - docs/types/test.ts | 166 - examples/index.js | 55 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 164 - lib/index.js | 77 - lib/limit.js | 142 - lib/main.js | 95 - lib/validate.js | 80 - package.json | 65 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 1095 ----- test/test.js | 38 - test/test.main.js | 1035 ----- test/test.validate.js | 181 - 50 files changed, 4873 insertions(+), 7178 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/limit.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 0a4d295..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-08-03T18:16:47.472Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1e08946..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 5358060..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index fa37f2d..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '37 1 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -460,7 +457,7 @@ reduceRightAsync( files, acc, read, done ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -531,11 +528,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right +[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right/tree/esm -[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce +[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index b155fd2..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var reduceRightAsync; - var arr; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - reduceRightAsync = factory( onItem ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - var acc; - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index af5c346..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var reduceRightAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=false', function benchmark( b ) { - var opts; - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'series': false - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var arr; - var len; - var acc; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'limit': 3 - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b8adcd2..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right" -%% click B href "https://github.com/stdlib-js/utils-async-reduce-right/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-reduce-right/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-reduce-right/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-reduce-right/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right -[production-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-async-reduce-right/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-async-reduce-right/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-async-reduce-right/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 47a072e..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import reduceRightAsync from '../docs/types/index'; -export = reduceRightAsync; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 530ca4d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var c=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var x=c(function(U,O){ -var R=require('@stdlib/assert-is-plain-object/dist'),h=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,k=require('@stdlib/assert-is-positive-integer/dist').isPrimitive,d=require('@stdlib/error-tools-fmtprodmsg/dist');function I(e,r){return R(r)?(h(r,"thisArg")&&(e.thisArg=r.thisArg),h(r,"series")&&(e.series=r.series,!j(e.series))?new TypeError(d('1RZ2o',"series",e.series)):h(r,"limit")&&(e.limit=r.limit,!k(e.limit))?new TypeError(d('1RZ3P',"limit",e.limit)):null):new TypeError(d('1RZ2V',r));}O.exports=I -});var P=c(function(W,E){ -var J=require("debug"),a=J("reduce-right-async:limit");function L(e,r,i,t,s){var f,m,v,n,u,g;if(n=e.length,a("Collection length: %d",n),n===0)return a("Finished processing a collection."),s(null,r);for(n0&&o();function o(){u-=1,a("Collection element %d: %s.",u,JSON.stringify(e[u])),t.length===3?t.call(i.thisArg,r,e[u],l):t.length===4?t.call(i.thisArg,r,e[u],u,l):t.call(i.thisArg,r,e[u],u,e,l);function l(w,A){if(!m){if(w)return m=!0,b(w);a("Accumulator: %s",JSON.stringify(A)),r=A,b()}}}function b(l){if(l)return a("Encountered an error: %s",l.message),s(l);if(f+=1,a("Processed %d of %d collection elements.",f,n),u>0)return o();if(f===n)return a("Finished processing a collection."),s(null,r)}}E.exports=L -});var q=c(function(X,F){ -var T=require('@stdlib/assert-is-function/dist'),S=require('@stdlib/assert-is-collection/dist'),y=require('@stdlib/error-tools-fmtprodmsg/dist'),B=require('@stdlib/constants-float64-pinf/dist'),z=x(),D=P();function G(e,r){var i,t,s;if(i={},arguments.length>1){if(t=z(i,e),t)throw t;s=r}else s=e;if(!T(s))throw new TypeError(y('1RZ3q',s));return i.series===void 0&&i.limit===void 0&&(i.series=!0),i.series?i.limit=1:i.limit||(i.limit=B),f;function f(m,v,n){if(!S(m))throw new TypeError(y('1RZAh',m));if(!T(n))throw new TypeError(y('1RZ3q',n));return D(m,v,i,s,u);function u(g,o){if(g)return n(g);n(null,o)}}}F.exports=G -});var N=c(function(Y,C){ -var p=q();function H(e,r,i,t,s){if(arguments.length<5)return p(i)(e,r,t);p(i,t)(e,r,s)}C.exports=H -});var K=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),V=N(),M=q();K(V,"factory",M);module.exports=V; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index acb9d67..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/limit.js", "../lib/factory.js", "../lib/main.js", "../lib/index.js"], - "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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\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 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 to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\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 === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, 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 ( !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, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\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* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nmodule.exports = reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' );\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, 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"], - "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,0BAA2B,EAkB/C,SAASE,EAAOC,EAAYC,EAAKC,EAAMC,EAAKC,EAAO,CAClD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMR,EAAW,OACjBF,EAAO,wBAAyBU,CAAI,EAE/BA,IAAQ,EACZ,OAAAV,EAAO,mCAAoC,EACpCM,EAAM,KAAMH,CAAI,EAYxB,IAVKO,EAAMN,EAAK,MACfK,EAAMC,EAEND,EAAML,EAAK,MAEZJ,EAAO,wBAAyBS,CAAI,EACpCT,EAAO,0BAA2BK,EAAI,MAAO,EAE7CE,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVE,EAAK,EAQP,SAASA,GAAO,CACfF,GAAO,EACPX,EAAO,6BAA8BW,EAAK,KAAK,UAAWT,EAAYS,CAAI,CAAE,CAAE,EACzEN,EAAI,SAAW,EACnBA,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGG,CAAG,EACxCT,EAAI,SAAW,EAC1BA,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGA,EAAKG,CAAG,EAExDT,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGA,EAAKT,EAAYY,CAAG,EAUrE,SAASA,EAAIC,EAAOC,EAAS,CAC5B,GAAK,CAAAR,EAIL,IAAKO,EACJ,OAAAP,EAAM,GACCS,EAAMF,CAAM,EAEpBf,EAAO,kBAAmB,KAAK,UAAWgB,CAAO,CAAE,EACnDb,EAAMa,EACNC,EAAK,EACN,CACD,CASA,SAASA,EAAMF,EAAQ,CACtB,GAAKA,EACJ,OAAAf,EAAO,2BAA4Be,EAAM,OAAQ,EAC1CT,EAAMS,CAAM,EAIpB,GAFAR,GAAS,EACTP,EAAO,0CAA2CO,EAAOG,CAAI,EACxDC,EAAM,EACV,OAAOE,EAAK,EAEb,GAAKN,IAAUG,EACd,OAAAV,EAAO,mCAAoC,EACpCM,EAAM,KAAMH,CAAI,CAEzB,CACD,CAKAL,EAAO,QAAUG,IC7IjB,IAAAiB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,gCAAiC,EACjDC,EAAW,IACXC,EAAQ,IAoEZ,SAASC,EAASC,EAASC,EAAM,CAChC,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,CAACP,EAAYW,CAAE,EACnB,MAAM,IAAI,UAAWT,EAAQ,mEAAoES,CAAE,CAAE,EAEtG,OAAKF,EAAK,SAAW,QAAUA,EAAK,QAAU,SAC7CA,EAAK,OAAS,IAEVA,EAAK,OACTA,EAAK,MAAQ,EACDA,EAAK,QACjBA,EAAK,MAAQN,GAEPS,EAaP,SAASA,EAAkBC,EAAYC,EAASC,EAAO,CACtD,GAAK,CAACd,EAAcY,CAAW,EAC9B,MAAM,IAAI,UAAWX,EAAQ,sEAAuEW,CAAW,CAAE,EAElH,GAAK,CAACb,EAAYe,CAAK,EACtB,MAAM,IAAI,UAAWb,EAAQ,mEAAoEa,CAAK,CAAE,EAEzG,OAAOV,EAAOQ,EAAYC,EAASL,EAAME,EAAGK,CAAK,EAUjD,SAASA,EAAMC,EAAOC,EAAM,CAC3B,GAAKD,EACJ,OAAOF,EAAME,CAAM,EAEpBF,EAAM,KAAMG,CAAI,CACjB,CACD,CACD,CAKAnB,EAAO,QAAUO,ICnKjB,IAAAa,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,IA8Dd,SAASC,EAAkBC,EAAYC,EAASC,EAASC,EAAKC,EAAO,CACpE,GAAK,UAAU,OAAS,EACvB,OAAON,EAASI,CAAQ,EAAGF,EAAYC,EAASE,CAAI,EAErDL,EAASI,EAASC,CAAI,EAAGH,EAAYC,EAASG,CAAK,CACpD,CAKAP,EAAO,QAAUE,IC9BjB,IAAIM,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "isPositiveInteger", "format", "validate", "opts", "options", "require_limit", "__commonJSMin", "exports", "module", "logger", "debug", "limit", "collection", "acc", "opts", "fcn", "done", "count", "flg", "lim", "len", "idx", "i", "next", "cb", "error", "result", "clbk", "require_factory", "__commonJSMin", "exports", "module", "isFunction", "isCollection", "format", "PINF", "validate", "limit", "factory", "options", "fcn", "opts", "err", "f", "reduceRightAsync", "collection", "initial", "done", "clbk", "error", "acc", "require_main", "__commonJSMin", "exports", "module", "factory", "reduceRightAsync", "collection", "initial", "options", "fcn", "done", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3f22669..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,224 +0,0 @@ - -{{alias}}( collection, initial, [options,] reducer, done ) - Applies a function against an accumulator and each element in a collection - and returns the accumulated result, iterating from right to left. - - When invoked, `reducer` is provided a maximum of five arguments: - - - `accumulator`: accumulated value - - `value`: collection value - - `index`: collection index - - `collection`: the input collection - - `next`: a callback to be invoked after processing a collection `value` - - The actual number of provided arguments depends on function length. If - `reducer` accepts three arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `next` - - If `reducer` accepts four arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `index` - - `next` - - For every other `reducer` signature, `reducer` is provided all five - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `accumulator`: accumulated value - - If a provided function calls the `next` callback with a truthy `error` - argument, the function suspends execution and immediately calls the `done` - callback for subsequent `error` handling. - - Execution is *not* guaranteed to be asynchronous. To guarantee asynchrony, - 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`). - - The function does not support dynamic collection resizing. - - If provided an empty collection, the function invokes the `done` callback - with the `initial` value as the second argument. - - The function does not skip `undefined` elements. - - When processing collection elements concurrently, *beware* of race - conditions when updating an accumulator. This is especially true when an - accumulator is a primitive (e.g., a number). In general, prefer object - accumulators. - - Parameters - ---------- - collection: Array|TypedArray|Object - Input collection over which to iterate. If provided an object, the - object must be array-like (excluding strings and functions). - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - reducer: Function - The function to invoke for each element in a collection. - - done: Function - A callback invoked either upon processing all collection elements or - upon encountering an error. - - Examples - -------- - // Basic usage: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, fcn, done ) - 3000 - 2500 - 1000 - 6500 - - // Limit number of concurrent invocations: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'limit': 2 }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 2500 - 3000 - 1000 - 6500 - - // Process concurrently: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'series': false }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 1000 - 2500 - 3000 - 6500 - - -{{alias}}.factory( [options,] fcn ) - Returns a function which applies a function against an accumulator and each - element in a collection and returns the accumulated result, iterating from - right to left. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - fcn: Function - The function to invoke for each element in a collection. - - Returns - ------- - out: Function - A function which invokes a function for each element in a collection. - - Examples - -------- - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > var opts = { 'series': false }; - > var f = {{alias}}.factory( opts, fcn ); - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > f( arr, acc, done ) - 1000 - 2500 - 3000 - 6500 - > acc = { 'sum': 0 }; - > arr = [ 1000, 1500, 2000 ]; - > f( arr, acc, done ) - 1000 - 1500 - 2000 - 4500 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0455864..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,166 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unsafe-assignment */ - -import reduceRightAsync = require( './index' ); - -const reducer = ( acc: any, value: number, index: number, next: Function ) => { - acc.sum += value; - if ( index === void 0 ) { - throw new Error( '`index` is missing.' ); - } - next( null, acc ); -}; - -const done = ( error: Error | null, acc: any ) => { - if ( error ) { - throw error; - } - if ( acc === void 0 ) { - throw new Error( '`acc` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( 2, acc, reducer, done ); // $ExpectError - reduceRightAsync( false, acc, reducer, done ); // $ExpectError - reduceRightAsync( true, acc, reducer, done ); // $ExpectError - reduceRightAsync( {}, acc, reducer, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a predicate argument which is not a predicate function... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 2, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, false, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, true, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 'abc', done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, [], done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a done callback argument which is not a function having a supported signature... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 2 ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, false ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, true ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 'abc' ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, {} ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, [] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const acc = { 'sum': 0 }; - reduceRightAsync(); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, reducer, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - reduceRightAsync.factory( reducer ); // $ExpectType FactoryFunction - reduceRightAsync.factory( { 'series': true }, reducer ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - reduceRightAsync.factory( [], reducer ); // $ExpectError - reduceRightAsync.factory( 123, reducer ); // $ExpectError - reduceRightAsync.factory( 'abc', reducer ); // $ExpectError - reduceRightAsync.factory( false, reducer ); // $ExpectError - reduceRightAsync.factory( true, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not a predicate function... -{ - reduceRightAsync.factory( {} ); // $ExpectError - reduceRightAsync.factory( true ); // $ExpectError - reduceRightAsync.factory( false ); // $ExpectError - reduceRightAsync.factory( {}, 123 ); // $ExpectError - reduceRightAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1( 12, acc, done ); // $ExpectError - fcn1( true, acc, done ); // $ExpectError - fcn1( false, acc, done ); // $ExpectError - fcn1( {}, acc, done ); // $ExpectError - - fcn1( [ 3000, 2500, 1000 ], acc, 12 ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, true ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, false ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, '5' ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, {} ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, [] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1(); // $ExpectError - fcn1( [ 3000, 2500, 1000 ] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - reduceRightAsync.factory( { 'limit': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': true }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': false }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - reduceRightAsync.factory( { 'series': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': 12 }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - reduceRightAsync.factory(); // $ExpectError - reduceRightAsync.factory( {}, reducer, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index dd64345..0000000 --- a/examples/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var resolve = require( 'path' ).resolve; -var readFile = require( '@stdlib/fs-read-file' ); -var reduceRightAsync = require( './../lib' ); - -var files = [ - resolve( __dirname, '..', 'package.json' ), - resolve( __dirname, '..', 'README.md' ) -]; - -function done( error, acc ) { - if ( error ) { - throw error; - } - console.log( acc.count ); -} - -function read( acc, file, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( file, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( null, acc ); - } - acc.count += 1; - next( null, acc ); - } -} - -var acc = { - 'count': 0 -}; -reduceRightAsync( files, acc, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 28e0a36..f6cba5d 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..234a485 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as c}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";function m(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var d=m(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function f(e,m){var f,u,p;if(f={},arguments.length>1){if(u=function(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("1RZ2o","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!c(e.limit))?new TypeError(r("1RZ3P","limit",e.limit)):null):new TypeError(r("1RZ2V",t))}(f,e),u)throw u;p=m}else p=e;if(!t(p))throw new TypeError(r("1RZ3q",p));return void 0===f.series&&void 0===f.limit&&(f.series=!0),f.series?f.limit=1:f.limit||(f.limit=s),function(e,s,n){if(!i(e))throw new TypeError(r("1RZAh",e));if(!t(n))throw new TypeError(r("1RZ3q",n));return function(e,t,i,r,s){var n,o,l,c,m,f;if(c=e.length,d("Collection length: %d",c),0===c)return d("Finished processing a collection."),s(null,t);for(l=c0&&u();function u(){function s(e,i){if(!o){if(e)return o=!0,p(e);d("Accumulator: %s",JSON.stringify(i)),t=i,p()}}d("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function p(e){return e?(d("Encountered an error: %s",e.message),s(e)):(d("Processed %d of %d collection elements.",n+=1,c),m>0?u():n===c?(d("Finished processing a collection."),s(null,t)):void 0)}}(e,s,f,p,(function(e,t){if(e)return n(e);n(null,t)}))}}function u(e,t,i,r,s){if(arguments.length<5)return f(i)(e,t,r);f(i,r)(e,t,s)}e(u,"factory",f);export{u as default,f as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..e11f2cb --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/limit.js","../lib/factory.js","../lib/validate.js","../lib/main.js","../lib/index.js"],"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 logger = require( 'debug' );\n\n\n// VARIABLES //\n\nvar debug = logger( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RZ3q', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '1RZAh', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RZ3q', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '1RZ2V', 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( '1RZ2o', '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( '1RZ3P', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["debug","logger","factory","options","fcn","opts","err","f","arguments","length","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","validate","isFunction","PINF","collection","initial","done","isCollection","acc","count","flg","lim","len","idx","i","next","cb","error","result","clbk","JSON","stringify","call","message","reduceRightAsync","setReadOnly","main"],"mappings":";;81CA2BIA,uDAAQC,CAAQ,4BCoEpB,SAASC,EAASC,EAASC,GAC1B,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAA,EACFG,UAAUC,OAAS,EAAI,CAE3B,GADAH,EChDF,SAAmBD,EAAMF,GACxB,OAAMO,EAAUP,IAGXQ,EAAYR,EAAS,aACzBE,EAAKO,QAAUT,EAAQS,SAEnBD,EAAYR,EAAS,YACzBE,EAAKQ,OAASV,EAAQU,QAChBC,EAAWT,EAAKQ,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUX,EAAKQ,SAGnDF,EAAYR,EAAS,WACzBE,EAAKY,MAAQd,EAAQc,OACfC,EAAmBb,EAAKY,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASX,EAAKY,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASb,GAkBzC,CD4BQgB,CAAUd,EAAMF,GACjBG,EACJ,MAAMA,EAEPC,EAAIH,CACN,MACEG,EAAIJ,EAEL,IAAMiB,EAAYb,GACjB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAUvC,YARqB,IAAhBF,EAAKQ,aAAoC,IAAfR,EAAKY,QACnCZ,EAAKQ,QAAS,GAEVR,EAAKQ,OACTR,EAAKY,MAAQ,EACDZ,EAAKY,QACjBZ,EAAKY,MAAQI,GAed,SAA2BC,EAAYC,EAASC,GAC/C,IAAMC,EAAcH,GACnB,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,IAAMF,EAAYI,GACjB,MAAM,IAAIT,UAAWC,EAAQ,QAASQ,IAEvC,ODhGF,SAAgBF,EAAYI,EAAKrB,EAAMD,EAAKoB,GAC3C,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMR,EAAWb,OACjBT,EAAO,wBAAyB8B,GAEnB,IAARA,EAEJ,OADA9B,EAAO,qCACAwB,EAAM,KAAME,GAYpB,IATCG,EADIC,EAAMzB,EAAKY,MACTa,EAEAzB,EAAKY,MAEZjB,EAAO,wBAAyB6B,GAChC7B,EAAO,0BAA2BI,EAAIK,QAEtCkB,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVE,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKR,EAAL,CAIA,GAAKO,EAEJ,OADAP,GAAM,EACCS,EAAMF,GAEdnC,EAAO,kBAAmBsC,KAAKC,UAAWH,IAC1CV,EAAMU,EACNC,GAPC,CAQD,CA5BDrC,EAAO,6BADP+B,GAAO,EACmCO,KAAKC,UAAWjB,EAAYS,KAClD,IAAf3B,EAAIK,OACRL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOG,GACtB,IAAf9B,EAAIK,OACfL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKG,GAErD9B,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKT,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJnC,EAAO,2BAA4BmC,EAAMM,SAClCjB,EAAMW,KAGdnC,EAAO,0CADP2B,GAAS,EACgDG,GACpDC,EAAM,EACHE,IAEHN,IAAUG,GACd9B,EAAO,qCACAwB,EAAM,KAAME,SAFpB,EAIA,CACF,CCKST,CAAOK,EAAYC,EAASlB,EAAME,GAUzC,SAAe4B,EAAOT,GACrB,GAAKS,EACJ,OAAOX,EAAMW,GAEdX,EAAM,KAAME,EACZ,GACD,CACF,CE1EA,SAASgB,EAAkBpB,EAAYC,EAASpB,EAASC,EAAKoB,GAC7D,GAAKhB,UAAUC,OAAS,EACvB,OAAOP,EAASC,EAATD,CAAoBoB,EAAYC,EAASnB,GAEjDF,EAASC,EAASC,EAAlBF,CAAyBoB,EAAYC,EAASC,EAC/C,CClBAmB,EAAAC,EAAA,UAAA1C"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index e107128..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,164 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var validate = require( './validate.js' ); -var limit = require( './limit.js' ); - - -// MAIN // - -/** -* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} last argument must be a function -* @returns {Function} function which invokes the provided function once for each element in a collection -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error, data ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var opts = { -* 'series': false -* }; -* -* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: -* var reduceRightAsync = factory( opts, read ); -* -* // Create a collection over which to iterate: -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* // Define a callback which handles errors: -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* // Run `read` for each element in `files`: -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, done ); -*/ -function factory( options, fcn ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = fcn; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '1RZ3q', f ) ); - } - if ( opts.series === void 0 && opts.limit === void 0 ) { - opts.series = true; - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return reduceRightAsync; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * @private - * @param {Collection} collection - input collection - * @param {*} initial - initial value - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be a collection - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function reduceRightAsync( collection, initial, done ) { - if ( !isCollection( collection ) ) { - throw new TypeError( format( '1RZAh', collection ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '1RZ3q', done ) ); - } - return limit( collection, initial, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {*} [acc] - accumulated value - * @returns {void} - */ - function clbk( error, acc ) { - if ( error ) { - return done( error ); - } - done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ae657ff..0000000 --- a/lib/index.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* @module @stdlib/utils-async-reduce-right -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' ); -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/limit.js b/lib/limit.js deleted file mode 100644 index cdb60af..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); - - -// VARIABLES // - -var debug = logger( 'reduce-right-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each element in a collection, limiting the number of concurrently pending functions and iterating from right to left. -* -* @private -* @param {Collection} collection - input collection -* @param {*} acc - initial value -* @param {Options} opts - function options -* @param {*} [opts.thisArg] - execution context -* @param {PositiveInteger} [opts.limit] - maximum number of pending function invocations -* @param {Function} fcn - function to invoke -* @param {Callback} done - function to invoke upon completion or upon encountering an error -* @returns {void} -*/ -function limit( collection, acc, opts, fcn, done ) { - var count; - var flg; - var lim; - var len; - var idx; - var i; - - len = collection.length; - debug( 'Collection length: %d', len ); - - if ( len === 0 ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - count = 0; - idx = len; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all collection elements... - if ( idx > 0 ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next element in a collection. - * - * @private - */ - function next() { - idx -= 1; - debug( 'Collection element %d: %s.', idx, JSON.stringify( collection[ idx ] ) ); - if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], cb ); - } else if ( fcn.length === 4 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, cb ); - } else { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len - } - /** - * Callback invoked once a provided function finishes processing a collection element. - * - * @private - * @param {*} [error] - error - * @param {*} [result] - accumulation result - * @returns {void} - */ - function cb( error, result ) { - if ( flg ) { - // Prevent further processing of collection elements: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Accumulator: %s', JSON.stringify( result ) ); - acc = result; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next collection element. - * - * @private - * @param {*} [error] - error - * @returns {void} - */ - function clbk( error ) { - if ( error ) { - debug( 'Encountered an error: %s', error.message ); - return done( error ); - } - count += 1; - debug( 'Processed %d of %d collection elements.', count, len ); - if ( idx > 0 ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index c8b0d0f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param {Collection} collection - input collection -* @param {*} initial - initial value -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} second-to-last argument must be a function -* @throws {TypeError} last argument must be a function -* @returns {void} -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -function reduceRightAsync( collection, initial, options, fcn, done ) { - if ( arguments.length < 5 ) { - return factory( options )( collection, initial, fcn ); - } - factory( options, fcn )( collection, initial, done ); -} - - -// EXPORTS // - -module.exports = reduceRightAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 0c666fe..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @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 -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'thisArg': {}, -* 'series': false, -* 'limit': 10 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '1RZ2V', options ) ); - } - if ( hasOwnProp( options, 'thisArg' ) ) { - opts.thisArg = options.thisArg; - } - if ( hasOwnProp( options, 'series' ) ) { - opts.series = options.series; - if ( !isBoolean( opts.series ) ) { - return new TypeError( format( '1RZ2o', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '1RZ3P', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index addc507..563c57c 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,44 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-collection": "^0.2.2", - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/assert-is-positive-integer": "^0.2.2", - "@stdlib/constants-float64-pinf": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "debug": "^2.6.9", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/constants-float64-eps": "^0.2.2", - "@stdlib/fs-read-file": "^0.2.2", - "@stdlib/utils-noop": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..69bcdc8 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 8244931..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1095 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( {}, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, next ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - factory( opts, next ); - }; - } -}); - -tape( 'the function returns a function (no options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided a collection (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a collection (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (1 argument)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (2 arguments)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with five arguments', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn() { - var value; - var next; - var acc; - var k; - - acc = arguments[ 0 ]; - value = arguments[ 1 ]; - k = arguments[ 2 ]; - next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( k, i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the returned function supports processing collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements concurrently', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 100, 250, 300 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements sequentially (limit = 1)', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of collection elements which are processed at any one time', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 250, 300, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 250, 100, 300 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var reduceRightAsync; - var arr; - - reduceRightAsync = factory( fcn ); - arr = []; - - reduceRightAsync( arr, 0, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var reduceRightAsync; - var obj; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = []; - obj = {}; - reduceRightAsync( arr, obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - i = 0; - - reduceRightAsync( arr, {}, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, acc ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the returned function does not skip empty elements', function test( t ) { - var reduceRightAsync; - var expected; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index f273a40..0000000 --- a/test/test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof reduceRightAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 1893240..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1035 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a collection', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (no options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, next, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, 0 ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - reduceRightAsync( [ 1, 2, 3 ], 0, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (1 argument)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (2 arguments)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with five arguments', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn() { - var next; - var acc; - var v; - - next = arguments[ 4 ]; - acc = arguments[ 0 ]; - v = arguments[ 1 ]; - - i -= 1; - j += 1; - - t.strictEqual( v, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, v ); - - function onTimeout() { - acc.sum += v; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'by default, the function processes collection elements sequentially', function test( t ) { - var values; - var count; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements concurrently', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 100, 250, 300 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': true - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially (limit = 1)', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var arr; - var ctx; - - arr = [ 3, 2, 1 ]; - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 3, 2, 1 ]; - opts = { - 'series': true - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 250, 100, 300 ]; - opts = { - 'limit': 2 - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var arr = []; - reduceRightAsync( arr, 0, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var arr = []; - var obj = {}; - - reduceRightAsync( arr, obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - arr = [ 3, 2, 1 ]; - i = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, value ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the function does not skip empty elements', function test( t ) { - var expected; - var arr; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, fcn, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 7660838..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,181 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `limit` option which is not a positive integer', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - -5, - 0, - 3.14, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'limit': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `series` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'series': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function accepts any value for the `thisArg` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'thisArg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err, null, 'returns null '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'thisArg': {}, - 'series': false, - 'limit': 10 - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From db6828314cd7e5fee7664dcefe801ef10c3a8d2b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 04:31:33 +0000 Subject: [PATCH 124/147] Transform error messages --- lib/factory.js | 8 ++++---- lib/validate.js | 8 ++++---- package.json | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 1125052..e107128 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -22,7 +22,7 @@ var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var PINF = require( '@stdlib/constants-float64-pinf' ); var validate = require( './validate.js' ); var limit = require( './limit.js' ); @@ -109,7 +109,7 @@ function factory( options, fcn ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '1RZ3q', f ) ); } if ( opts.series === void 0 && opts.limit === void 0 ) { opts.series = true; @@ -134,10 +134,10 @@ function factory( options, fcn ) { */ function reduceRightAsync( collection, initial, done ) { if ( !isCollection( collection ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a collection. Value: `%s`.', collection ) ); + throw new TypeError( format( '1RZAh', collection ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '1RZ3q', done ) ); } return limit( collection, initial, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index 9ba927e..0c666fe 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,7 +54,7 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '1RZ2V', options ) ); } if ( hasOwnProp( options, 'thisArg' ) ) { opts.thisArg = options.thisArg; @@ -62,13 +62,13 @@ function validate( opts, options ) { if ( hasOwnProp( options, 'series' ) ) { opts.series = options.series; if ( !isBoolean( opts.series ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'series', opts.series ) ); + return new TypeError( format( '1RZ2o', 'series', opts.series ) ); } } if ( hasOwnProp( options, 'limit' ) ) { opts.limit = options.limit; if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'limit', opts.limit ) ); + return new TypeError( format( '1RZ3P', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index 739500e..0c316c5 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-plain-object": "^0.2.2", "@stdlib/assert-is-positive-integer": "^0.2.2", "@stdlib/constants-float64-pinf": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.1", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", "debug": "^2.6.9", From 17e49cca5f47700eb49b1cc4f3b2a61198653df6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 08:09:28 +0000 Subject: [PATCH 125/147] Remove files --- index.d.ts | 410 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5257 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index f6cba5d..0000000 --- a/index.d.ts +++ /dev/null @@ -1,410 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Execution context. - */ - thisArg?: ThisParameterType>; - - /** - * The maximum number of pending invocations at any one time. - */ - limit?: number; - - /** - * Boolean indicating whether to sequentially invoke the reducer function for each `collection` element. If `true`, the function sets `options.limit=1`. Default: true. - */ - series?: boolean; -} - -/** -* Callback function. -*/ -type Nullary = () => void; - -/** -* Callback function. -* -* @param error - encountered error or null -*/ -type Unary = ( error: Error | null ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Binary = ( error: Error | null, accumulator: U ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param next - a callback to be invoked after processing a collection `value` -*/ -type TernaryReducer = ( this: V, accumulator: U, value: T, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuaternaryReducer = ( this: V, accumulator: U, value: T, index: number, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuinaryReducer = ( this: V, accumulator: U, value: T, index: number, collection: Collection, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type Reducer = TernaryReducer | QuaternaryReducer | QuinaryReducer; - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result. -* -* @param collection - input collection -* @param initial - initial value -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( collection: Collection, initial: U, done: Callback ) => void; - -/** -* Interface for `reduceRightAsync`. -*/ -interface ReduceRightAsync { - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, {}, read, done ); - */ - ( collection: Collection, initial: U, options: Options, reducer: Reducer, done: Callback ): void; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, read, done ); - */ - ( collection: Collection, initial: U, reducer: Reducer, done: Callback ): void; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @throws must provide valid options - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var opts = { - * 'series': false - * }; - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( opts, read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( options: Options, reducer: Reducer ): FactoryFunction; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param reducer - function to invoke for each element in a collection - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( reducer: Reducer ): FactoryFunction; -} - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param collection - input collection -* @param initial - initial value -* @param options - function options -* @param options.thisArg - execution context -* @param options.limit - maximum number of pending invocations at any one time -* @param 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 (default: true) -* @param reducer - function to invoke for each element in a collection -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -declare var reduceRightAsync: ReduceRightAsync; - - -// EXPORTS // - -export = reduceRightAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 234a485..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as c}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";function m(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var d=m(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function f(e,m){var f,u,p;if(f={},arguments.length>1){if(u=function(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("1RZ2o","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!c(e.limit))?new TypeError(r("1RZ3P","limit",e.limit)):null):new TypeError(r("1RZ2V",t))}(f,e),u)throw u;p=m}else p=e;if(!t(p))throw new TypeError(r("1RZ3q",p));return void 0===f.series&&void 0===f.limit&&(f.series=!0),f.series?f.limit=1:f.limit||(f.limit=s),function(e,s,n){if(!i(e))throw new TypeError(r("1RZAh",e));if(!t(n))throw new TypeError(r("1RZ3q",n));return function(e,t,i,r,s){var n,o,l,c,m,f;if(c=e.length,d("Collection length: %d",c),0===c)return d("Finished processing a collection."),s(null,t);for(l=c0&&u();function u(){function s(e,i){if(!o){if(e)return o=!0,p(e);d("Accumulator: %s",JSON.stringify(i)),t=i,p()}}d("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function p(e){return e?(d("Encountered an error: %s",e.message),s(e)):(d("Processed %d of %d collection elements.",n+=1,c),m>0?u():n===c?(d("Finished processing a collection."),s(null,t)):void 0)}}(e,s,f,p,(function(e,t){if(e)return n(e);n(null,t)}))}}function u(e,t,i,r,s){if(arguments.length<5)return f(i)(e,t,r);f(i,r)(e,t,s)}e(u,"factory",f);export{u as default,f as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index e11f2cb..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/limit.js","../lib/factory.js","../lib/validate.js","../lib/main.js","../lib/index.js"],"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 logger = require( 'debug' );\n\n\n// VARIABLES //\n\nvar debug = logger( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RZ3q', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '1RZAh', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RZ3q', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '1RZ2V', 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( '1RZ2o', '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( '1RZ3P', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["debug","logger","factory","options","fcn","opts","err","f","arguments","length","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","validate","isFunction","PINF","collection","initial","done","isCollection","acc","count","flg","lim","len","idx","i","next","cb","error","result","clbk","JSON","stringify","call","message","reduceRightAsync","setReadOnly","main"],"mappings":";;81CA2BIA,uDAAQC,CAAQ,4BCoEpB,SAASC,EAASC,EAASC,GAC1B,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAA,EACFG,UAAUC,OAAS,EAAI,CAE3B,GADAH,EChDF,SAAmBD,EAAMF,GACxB,OAAMO,EAAUP,IAGXQ,EAAYR,EAAS,aACzBE,EAAKO,QAAUT,EAAQS,SAEnBD,EAAYR,EAAS,YACzBE,EAAKQ,OAASV,EAAQU,QAChBC,EAAWT,EAAKQ,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUX,EAAKQ,SAGnDF,EAAYR,EAAS,WACzBE,EAAKY,MAAQd,EAAQc,OACfC,EAAmBb,EAAKY,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASX,EAAKY,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASb,GAkBzC,CD4BQgB,CAAUd,EAAMF,GACjBG,EACJ,MAAMA,EAEPC,EAAIH,CACN,MACEG,EAAIJ,EAEL,IAAMiB,EAAYb,GACjB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAUvC,YARqB,IAAhBF,EAAKQ,aAAoC,IAAfR,EAAKY,QACnCZ,EAAKQ,QAAS,GAEVR,EAAKQ,OACTR,EAAKY,MAAQ,EACDZ,EAAKY,QACjBZ,EAAKY,MAAQI,GAed,SAA2BC,EAAYC,EAASC,GAC/C,IAAMC,EAAcH,GACnB,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,IAAMF,EAAYI,GACjB,MAAM,IAAIT,UAAWC,EAAQ,QAASQ,IAEvC,ODhGF,SAAgBF,EAAYI,EAAKrB,EAAMD,EAAKoB,GAC3C,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMR,EAAWb,OACjBT,EAAO,wBAAyB8B,GAEnB,IAARA,EAEJ,OADA9B,EAAO,qCACAwB,EAAM,KAAME,GAYpB,IATCG,EADIC,EAAMzB,EAAKY,MACTa,EAEAzB,EAAKY,MAEZjB,EAAO,wBAAyB6B,GAChC7B,EAAO,0BAA2BI,EAAIK,QAEtCkB,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVE,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKR,EAAL,CAIA,GAAKO,EAEJ,OADAP,GAAM,EACCS,EAAMF,GAEdnC,EAAO,kBAAmBsC,KAAKC,UAAWH,IAC1CV,EAAMU,EACNC,GAPC,CAQD,CA5BDrC,EAAO,6BADP+B,GAAO,EACmCO,KAAKC,UAAWjB,EAAYS,KAClD,IAAf3B,EAAIK,OACRL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOG,GACtB,IAAf9B,EAAIK,OACfL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKG,GAErD9B,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKT,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJnC,EAAO,2BAA4BmC,EAAMM,SAClCjB,EAAMW,KAGdnC,EAAO,0CADP2B,GAAS,EACgDG,GACpDC,EAAM,EACHE,IAEHN,IAAUG,GACd9B,EAAO,qCACAwB,EAAM,KAAME,SAFpB,EAIA,CACF,CCKST,CAAOK,EAAYC,EAASlB,EAAME,GAUzC,SAAe4B,EAAOT,GACrB,GAAKS,EACJ,OAAOX,EAAMW,GAEdX,EAAM,KAAME,EACZ,GACD,CACF,CE1EA,SAASgB,EAAkBpB,EAAYC,EAASpB,EAASC,EAAKoB,GAC7D,GAAKhB,UAAUC,OAAS,EACvB,OAAOP,EAASC,EAATD,CAAoBoB,EAAYC,EAASnB,GAEjDF,EAASC,EAASC,EAAlBF,CAAyBoB,EAAYC,EAASC,EAC/C,CClBAmB,EAAAC,EAAA,UAAA1C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 69bcdc8..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 63cc4976525e099e6b1a030d51a9b256b2ced74b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 08:09:43 +0000 Subject: [PATCH 126/147] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 211 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.factory.js | 73 - benchmark/benchmark.js | 160 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 224 - docs/types/test.ts | 166 - examples/index.js | 55 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 164 - lib/index.js | 77 - lib/limit.js | 142 - lib/main.js | 95 - lib/validate.js | 80 - package.json | 65 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 1095 ----- test/test.js | 38 - test/test.main.js | 1035 ----- test/test.validate.js | 181 - 50 files changed, 4873 insertions(+), 7177 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/limit.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 404a1d8..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-09-01T03:21:08.371Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1e08946..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 5358060..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index fa37f2d..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '37 1 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -460,7 +457,7 @@ reduceRightAsync( files, acc, read, done ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -531,11 +528,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right +[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right/tree/esm -[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce +[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index b155fd2..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var reduceRightAsync; - var arr; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - reduceRightAsync = factory( onItem ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - var acc; - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index af5c346..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var reduceRightAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=false', function benchmark( b ) { - var opts; - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'series': false - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var arr; - var len; - var acc; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'limit': 3 - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b8adcd2..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right" -%% click B href "https://github.com/stdlib-js/utils-async-reduce-right/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-reduce-right/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-reduce-right/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-reduce-right/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right -[production-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-async-reduce-right/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-async-reduce-right/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-async-reduce-right/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 47a072e..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import reduceRightAsync from '../docs/types/index'; -export = reduceRightAsync; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 530ca4d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var c=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var x=c(function(U,O){ -var R=require('@stdlib/assert-is-plain-object/dist'),h=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,k=require('@stdlib/assert-is-positive-integer/dist').isPrimitive,d=require('@stdlib/error-tools-fmtprodmsg/dist');function I(e,r){return R(r)?(h(r,"thisArg")&&(e.thisArg=r.thisArg),h(r,"series")&&(e.series=r.series,!j(e.series))?new TypeError(d('1RZ2o',"series",e.series)):h(r,"limit")&&(e.limit=r.limit,!k(e.limit))?new TypeError(d('1RZ3P',"limit",e.limit)):null):new TypeError(d('1RZ2V',r));}O.exports=I -});var P=c(function(W,E){ -var J=require("debug"),a=J("reduce-right-async:limit");function L(e,r,i,t,s){var f,m,v,n,u,g;if(n=e.length,a("Collection length: %d",n),n===0)return a("Finished processing a collection."),s(null,r);for(n0&&o();function o(){u-=1,a("Collection element %d: %s.",u,JSON.stringify(e[u])),t.length===3?t.call(i.thisArg,r,e[u],l):t.length===4?t.call(i.thisArg,r,e[u],u,l):t.call(i.thisArg,r,e[u],u,e,l);function l(w,A){if(!m){if(w)return m=!0,b(w);a("Accumulator: %s",JSON.stringify(A)),r=A,b()}}}function b(l){if(l)return a("Encountered an error: %s",l.message),s(l);if(f+=1,a("Processed %d of %d collection elements.",f,n),u>0)return o();if(f===n)return a("Finished processing a collection."),s(null,r)}}E.exports=L -});var q=c(function(X,F){ -var T=require('@stdlib/assert-is-function/dist'),S=require('@stdlib/assert-is-collection/dist'),y=require('@stdlib/error-tools-fmtprodmsg/dist'),B=require('@stdlib/constants-float64-pinf/dist'),z=x(),D=P();function G(e,r){var i,t,s;if(i={},arguments.length>1){if(t=z(i,e),t)throw t;s=r}else s=e;if(!T(s))throw new TypeError(y('1RZ3q',s));return i.series===void 0&&i.limit===void 0&&(i.series=!0),i.series?i.limit=1:i.limit||(i.limit=B),f;function f(m,v,n){if(!S(m))throw new TypeError(y('1RZAh',m));if(!T(n))throw new TypeError(y('1RZ3q',n));return D(m,v,i,s,u);function u(g,o){if(g)return n(g);n(null,o)}}}F.exports=G -});var N=c(function(Y,C){ -var p=q();function H(e,r,i,t,s){if(arguments.length<5)return p(i)(e,r,t);p(i,t)(e,r,s)}C.exports=H -});var K=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),V=N(),M=q();K(V,"factory",M);module.exports=V; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index acb9d67..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/limit.js", "../lib/factory.js", "../lib/main.js", "../lib/index.js"], - "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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\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 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 to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\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 === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, 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 ( !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, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\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* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nmodule.exports = reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' );\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, 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"], - "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,0BAA2B,EAkB/C,SAASE,EAAOC,EAAYC,EAAKC,EAAMC,EAAKC,EAAO,CAClD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMR,EAAW,OACjBF,EAAO,wBAAyBU,CAAI,EAE/BA,IAAQ,EACZ,OAAAV,EAAO,mCAAoC,EACpCM,EAAM,KAAMH,CAAI,EAYxB,IAVKO,EAAMN,EAAK,MACfK,EAAMC,EAEND,EAAML,EAAK,MAEZJ,EAAO,wBAAyBS,CAAI,EACpCT,EAAO,0BAA2BK,EAAI,MAAO,EAE7CE,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVE,EAAK,EAQP,SAASA,GAAO,CACfF,GAAO,EACPX,EAAO,6BAA8BW,EAAK,KAAK,UAAWT,EAAYS,CAAI,CAAE,CAAE,EACzEN,EAAI,SAAW,EACnBA,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGG,CAAG,EACxCT,EAAI,SAAW,EAC1BA,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGA,EAAKG,CAAG,EAExDT,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGA,EAAKT,EAAYY,CAAG,EAUrE,SAASA,EAAIC,EAAOC,EAAS,CAC5B,GAAK,CAAAR,EAIL,IAAKO,EACJ,OAAAP,EAAM,GACCS,EAAMF,CAAM,EAEpBf,EAAO,kBAAmB,KAAK,UAAWgB,CAAO,CAAE,EACnDb,EAAMa,EACNC,EAAK,EACN,CACD,CASA,SAASA,EAAMF,EAAQ,CACtB,GAAKA,EACJ,OAAAf,EAAO,2BAA4Be,EAAM,OAAQ,EAC1CT,EAAMS,CAAM,EAIpB,GAFAR,GAAS,EACTP,EAAO,0CAA2CO,EAAOG,CAAI,EACxDC,EAAM,EACV,OAAOE,EAAK,EAEb,GAAKN,IAAUG,EACd,OAAAV,EAAO,mCAAoC,EACpCM,EAAM,KAAMH,CAAI,CAEzB,CACD,CAKAL,EAAO,QAAUG,IC7IjB,IAAAiB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,gCAAiC,EACjDC,EAAW,IACXC,EAAQ,IAoEZ,SAASC,EAASC,EAASC,EAAM,CAChC,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,CAACP,EAAYW,CAAE,EACnB,MAAM,IAAI,UAAWT,EAAQ,mEAAoES,CAAE,CAAE,EAEtG,OAAKF,EAAK,SAAW,QAAUA,EAAK,QAAU,SAC7CA,EAAK,OAAS,IAEVA,EAAK,OACTA,EAAK,MAAQ,EACDA,EAAK,QACjBA,EAAK,MAAQN,GAEPS,EAaP,SAASA,EAAkBC,EAAYC,EAASC,EAAO,CACtD,GAAK,CAACd,EAAcY,CAAW,EAC9B,MAAM,IAAI,UAAWX,EAAQ,sEAAuEW,CAAW,CAAE,EAElH,GAAK,CAACb,EAAYe,CAAK,EACtB,MAAM,IAAI,UAAWb,EAAQ,mEAAoEa,CAAK,CAAE,EAEzG,OAAOV,EAAOQ,EAAYC,EAASL,EAAME,EAAGK,CAAK,EAUjD,SAASA,EAAMC,EAAOC,EAAM,CAC3B,GAAKD,EACJ,OAAOF,EAAME,CAAM,EAEpBF,EAAM,KAAMG,CAAI,CACjB,CACD,CACD,CAKAnB,EAAO,QAAUO,ICnKjB,IAAAa,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,IA8Dd,SAASC,EAAkBC,EAAYC,EAASC,EAASC,EAAKC,EAAO,CACpE,GAAK,UAAU,OAAS,EACvB,OAAON,EAASI,CAAQ,EAAGF,EAAYC,EAASE,CAAI,EAErDL,EAASI,EAASC,CAAI,EAAGH,EAAYC,EAASG,CAAK,CACpD,CAKAP,EAAO,QAAUE,IC9BjB,IAAIM,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "isPositiveInteger", "format", "validate", "opts", "options", "require_limit", "__commonJSMin", "exports", "module", "logger", "debug", "limit", "collection", "acc", "opts", "fcn", "done", "count", "flg", "lim", "len", "idx", "i", "next", "cb", "error", "result", "clbk", "require_factory", "__commonJSMin", "exports", "module", "isFunction", "isCollection", "format", "PINF", "validate", "limit", "factory", "options", "fcn", "opts", "err", "f", "reduceRightAsync", "collection", "initial", "done", "clbk", "error", "acc", "require_main", "__commonJSMin", "exports", "module", "factory", "reduceRightAsync", "collection", "initial", "options", "fcn", "done", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 3f22669..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,224 +0,0 @@ - -{{alias}}( collection, initial, [options,] reducer, done ) - Applies a function against an accumulator and each element in a collection - and returns the accumulated result, iterating from right to left. - - When invoked, `reducer` is provided a maximum of five arguments: - - - `accumulator`: accumulated value - - `value`: collection value - - `index`: collection index - - `collection`: the input collection - - `next`: a callback to be invoked after processing a collection `value` - - The actual number of provided arguments depends on function length. If - `reducer` accepts three arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `next` - - If `reducer` accepts four arguments, `reducer` is provided: - - - `accumulator` - - `value` - - `index` - - `next` - - For every other `reducer` signature, `reducer` is provided all five - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `accumulator`: accumulated value - - If a provided function calls the `next` callback with a truthy `error` - argument, the function suspends execution and immediately calls the `done` - callback for subsequent `error` handling. - - Execution is *not* guaranteed to be asynchronous. To guarantee asynchrony, - 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`). - - The function does not support dynamic collection resizing. - - If provided an empty collection, the function invokes the `done` callback - with the `initial` value as the second argument. - - The function does not skip `undefined` elements. - - When processing collection elements concurrently, *beware* of race - conditions when updating an accumulator. This is especially true when an - accumulator is a primitive (e.g., a number). In general, prefer object - accumulators. - - Parameters - ---------- - collection: Array|TypedArray|Object - Input collection over which to iterate. If provided an object, the - object must be array-like (excluding strings and functions). - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - reducer: Function - The function to invoke for each element in a collection. - - done: Function - A callback invoked either upon processing all collection elements or - upon encountering an error. - - Examples - -------- - // Basic usage: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, fcn, done ) - 3000 - 2500 - 1000 - 6500 - - // Limit number of concurrent invocations: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'limit': 2 }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 2500 - 3000 - 1000 - 6500 - - // Process concurrently: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'series': false }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 1000 - 2500 - 3000 - 6500 - - -{{alias}}.factory( [options,] fcn ) - Returns a function which applies a function against an accumulator and each - element in a collection and returns the accumulated result, iterating from - right to left. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - fcn: Function - The function to invoke for each element in a collection. - - Returns - ------- - out: Function - A function which invokes a function for each element in a collection. - - Examples - -------- - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > var opts = { 'series': false }; - > var f = {{alias}}.factory( opts, fcn ); - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > f( arr, acc, done ) - 1000 - 2500 - 3000 - 6500 - > acc = { 'sum': 0 }; - > arr = [ 1000, 1500, 2000 ]; - > f( arr, acc, done ) - 1000 - 1500 - 2000 - 4500 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0455864..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,166 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unsafe-assignment */ - -import reduceRightAsync = require( './index' ); - -const reducer = ( acc: any, value: number, index: number, next: Function ) => { - acc.sum += value; - if ( index === void 0 ) { - throw new Error( '`index` is missing.' ); - } - next( null, acc ); -}; - -const done = ( error: Error | null, acc: any ) => { - if ( error ) { - throw error; - } - if ( acc === void 0 ) { - throw new Error( '`acc` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( 2, acc, reducer, done ); // $ExpectError - reduceRightAsync( false, acc, reducer, done ); // $ExpectError - reduceRightAsync( true, acc, reducer, done ); // $ExpectError - reduceRightAsync( {}, acc, reducer, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a predicate argument which is not a predicate function... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 2, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, false, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, true, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 'abc', done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, [], done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a done callback argument which is not a function having a supported signature... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 2 ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, false ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, true ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 'abc' ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, {} ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, [] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const acc = { 'sum': 0 }; - reduceRightAsync(); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, reducer, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - reduceRightAsync.factory( reducer ); // $ExpectType FactoryFunction - reduceRightAsync.factory( { 'series': true }, reducer ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - reduceRightAsync.factory( [], reducer ); // $ExpectError - reduceRightAsync.factory( 123, reducer ); // $ExpectError - reduceRightAsync.factory( 'abc', reducer ); // $ExpectError - reduceRightAsync.factory( false, reducer ); // $ExpectError - reduceRightAsync.factory( true, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not a predicate function... -{ - reduceRightAsync.factory( {} ); // $ExpectError - reduceRightAsync.factory( true ); // $ExpectError - reduceRightAsync.factory( false ); // $ExpectError - reduceRightAsync.factory( {}, 123 ); // $ExpectError - reduceRightAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1( 12, acc, done ); // $ExpectError - fcn1( true, acc, done ); // $ExpectError - fcn1( false, acc, done ); // $ExpectError - fcn1( {}, acc, done ); // $ExpectError - - fcn1( [ 3000, 2500, 1000 ], acc, 12 ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, true ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, false ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, '5' ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, {} ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, [] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1(); // $ExpectError - fcn1( [ 3000, 2500, 1000 ] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - reduceRightAsync.factory( { 'limit': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': true }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': false }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - reduceRightAsync.factory( { 'series': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': 12 }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - reduceRightAsync.factory(); // $ExpectError - reduceRightAsync.factory( {}, reducer, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index dd64345..0000000 --- a/examples/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var resolve = require( 'path' ).resolve; -var readFile = require( '@stdlib/fs-read-file' ); -var reduceRightAsync = require( './../lib' ); - -var files = [ - resolve( __dirname, '..', 'package.json' ), - resolve( __dirname, '..', 'README.md' ) -]; - -function done( error, acc ) { - if ( error ) { - throw error; - } - console.log( acc.count ); -} - -function read( acc, file, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( file, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( null, acc ); - } - acc.count += 1; - next( null, acc ); - } -} - -var acc = { - 'count': 0 -}; -reduceRightAsync( files, acc, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 28e0a36..f6cba5d 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..234a485 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as c}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";function m(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var d=m(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function f(e,m){var f,u,p;if(f={},arguments.length>1){if(u=function(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("1RZ2o","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!c(e.limit))?new TypeError(r("1RZ3P","limit",e.limit)):null):new TypeError(r("1RZ2V",t))}(f,e),u)throw u;p=m}else p=e;if(!t(p))throw new TypeError(r("1RZ3q",p));return void 0===f.series&&void 0===f.limit&&(f.series=!0),f.series?f.limit=1:f.limit||(f.limit=s),function(e,s,n){if(!i(e))throw new TypeError(r("1RZAh",e));if(!t(n))throw new TypeError(r("1RZ3q",n));return function(e,t,i,r,s){var n,o,l,c,m,f;if(c=e.length,d("Collection length: %d",c),0===c)return d("Finished processing a collection."),s(null,t);for(l=c0&&u();function u(){function s(e,i){if(!o){if(e)return o=!0,p(e);d("Accumulator: %s",JSON.stringify(i)),t=i,p()}}d("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function p(e){return e?(d("Encountered an error: %s",e.message),s(e)):(d("Processed %d of %d collection elements.",n+=1,c),m>0?u():n===c?(d("Finished processing a collection."),s(null,t)):void 0)}}(e,s,f,p,(function(e,t){if(e)return n(e);n(null,t)}))}}function u(e,t,i,r,s){if(arguments.length<5)return f(i)(e,t,r);f(i,r)(e,t,s)}e(u,"factory",f);export{u as default,f as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..e11f2cb --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/limit.js","../lib/factory.js","../lib/validate.js","../lib/main.js","../lib/index.js"],"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 logger = require( 'debug' );\n\n\n// VARIABLES //\n\nvar debug = logger( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RZ3q', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '1RZAh', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RZ3q', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '1RZ2V', 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( '1RZ2o', '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( '1RZ3P', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["debug","logger","factory","options","fcn","opts","err","f","arguments","length","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","validate","isFunction","PINF","collection","initial","done","isCollection","acc","count","flg","lim","len","idx","i","next","cb","error","result","clbk","JSON","stringify","call","message","reduceRightAsync","setReadOnly","main"],"mappings":";;81CA2BIA,uDAAQC,CAAQ,4BCoEpB,SAASC,EAASC,EAASC,GAC1B,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAA,EACFG,UAAUC,OAAS,EAAI,CAE3B,GADAH,EChDF,SAAmBD,EAAMF,GACxB,OAAMO,EAAUP,IAGXQ,EAAYR,EAAS,aACzBE,EAAKO,QAAUT,EAAQS,SAEnBD,EAAYR,EAAS,YACzBE,EAAKQ,OAASV,EAAQU,QAChBC,EAAWT,EAAKQ,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUX,EAAKQ,SAGnDF,EAAYR,EAAS,WACzBE,EAAKY,MAAQd,EAAQc,OACfC,EAAmBb,EAAKY,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASX,EAAKY,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASb,GAkBzC,CD4BQgB,CAAUd,EAAMF,GACjBG,EACJ,MAAMA,EAEPC,EAAIH,CACN,MACEG,EAAIJ,EAEL,IAAMiB,EAAYb,GACjB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAUvC,YARqB,IAAhBF,EAAKQ,aAAoC,IAAfR,EAAKY,QACnCZ,EAAKQ,QAAS,GAEVR,EAAKQ,OACTR,EAAKY,MAAQ,EACDZ,EAAKY,QACjBZ,EAAKY,MAAQI,GAed,SAA2BC,EAAYC,EAASC,GAC/C,IAAMC,EAAcH,GACnB,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,IAAMF,EAAYI,GACjB,MAAM,IAAIT,UAAWC,EAAQ,QAASQ,IAEvC,ODhGF,SAAgBF,EAAYI,EAAKrB,EAAMD,EAAKoB,GAC3C,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMR,EAAWb,OACjBT,EAAO,wBAAyB8B,GAEnB,IAARA,EAEJ,OADA9B,EAAO,qCACAwB,EAAM,KAAME,GAYpB,IATCG,EADIC,EAAMzB,EAAKY,MACTa,EAEAzB,EAAKY,MAEZjB,EAAO,wBAAyB6B,GAChC7B,EAAO,0BAA2BI,EAAIK,QAEtCkB,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVE,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKR,EAAL,CAIA,GAAKO,EAEJ,OADAP,GAAM,EACCS,EAAMF,GAEdnC,EAAO,kBAAmBsC,KAAKC,UAAWH,IAC1CV,EAAMU,EACNC,GAPC,CAQD,CA5BDrC,EAAO,6BADP+B,GAAO,EACmCO,KAAKC,UAAWjB,EAAYS,KAClD,IAAf3B,EAAIK,OACRL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOG,GACtB,IAAf9B,EAAIK,OACfL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKG,GAErD9B,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKT,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJnC,EAAO,2BAA4BmC,EAAMM,SAClCjB,EAAMW,KAGdnC,EAAO,0CADP2B,GAAS,EACgDG,GACpDC,EAAM,EACHE,IAEHN,IAAUG,GACd9B,EAAO,qCACAwB,EAAM,KAAME,SAFpB,EAIA,CACF,CCKST,CAAOK,EAAYC,EAASlB,EAAME,GAUzC,SAAe4B,EAAOT,GACrB,GAAKS,EACJ,OAAOX,EAAMW,GAEdX,EAAM,KAAME,EACZ,GACD,CACF,CE1EA,SAASgB,EAAkBpB,EAAYC,EAASpB,EAASC,EAAKoB,GAC7D,GAAKhB,UAAUC,OAAS,EACvB,OAAOP,EAASC,EAATD,CAAoBoB,EAAYC,EAASnB,GAEjDF,EAASC,EAASC,EAAlBF,CAAyBoB,EAAYC,EAASC,EAC/C,CClBAmB,EAAAC,EAAA,UAAA1C"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index e107128..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,164 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var validate = require( './validate.js' ); -var limit = require( './limit.js' ); - - -// MAIN // - -/** -* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} last argument must be a function -* @returns {Function} function which invokes the provided function once for each element in a collection -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error, data ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var opts = { -* 'series': false -* }; -* -* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: -* var reduceRightAsync = factory( opts, read ); -* -* // Create a collection over which to iterate: -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* // Define a callback which handles errors: -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* // Run `read` for each element in `files`: -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, done ); -*/ -function factory( options, fcn ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = fcn; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '1RZ3q', f ) ); - } - if ( opts.series === void 0 && opts.limit === void 0 ) { - opts.series = true; - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return reduceRightAsync; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * @private - * @param {Collection} collection - input collection - * @param {*} initial - initial value - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be a collection - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function reduceRightAsync( collection, initial, done ) { - if ( !isCollection( collection ) ) { - throw new TypeError( format( '1RZAh', collection ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '1RZ3q', done ) ); - } - return limit( collection, initial, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {*} [acc] - accumulated value - * @returns {void} - */ - function clbk( error, acc ) { - if ( error ) { - return done( error ); - } - done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ae657ff..0000000 --- a/lib/index.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* @module @stdlib/utils-async-reduce-right -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' ); -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/limit.js b/lib/limit.js deleted file mode 100644 index cdb60af..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); - - -// VARIABLES // - -var debug = logger( 'reduce-right-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each element in a collection, limiting the number of concurrently pending functions and iterating from right to left. -* -* @private -* @param {Collection} collection - input collection -* @param {*} acc - initial value -* @param {Options} opts - function options -* @param {*} [opts.thisArg] - execution context -* @param {PositiveInteger} [opts.limit] - maximum number of pending function invocations -* @param {Function} fcn - function to invoke -* @param {Callback} done - function to invoke upon completion or upon encountering an error -* @returns {void} -*/ -function limit( collection, acc, opts, fcn, done ) { - var count; - var flg; - var lim; - var len; - var idx; - var i; - - len = collection.length; - debug( 'Collection length: %d', len ); - - if ( len === 0 ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - count = 0; - idx = len; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all collection elements... - if ( idx > 0 ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next element in a collection. - * - * @private - */ - function next() { - idx -= 1; - debug( 'Collection element %d: %s.', idx, JSON.stringify( collection[ idx ] ) ); - if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], cb ); - } else if ( fcn.length === 4 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, cb ); - } else { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len - } - /** - * Callback invoked once a provided function finishes processing a collection element. - * - * @private - * @param {*} [error] - error - * @param {*} [result] - accumulation result - * @returns {void} - */ - function cb( error, result ) { - if ( flg ) { - // Prevent further processing of collection elements: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Accumulator: %s', JSON.stringify( result ) ); - acc = result; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next collection element. - * - * @private - * @param {*} [error] - error - * @returns {void} - */ - function clbk( error ) { - if ( error ) { - debug( 'Encountered an error: %s', error.message ); - return done( error ); - } - count += 1; - debug( 'Processed %d of %d collection elements.', count, len ); - if ( idx > 0 ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index c8b0d0f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param {Collection} collection - input collection -* @param {*} initial - initial value -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} second-to-last argument must be a function -* @throws {TypeError} last argument must be a function -* @returns {void} -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -function reduceRightAsync( collection, initial, options, fcn, done ) { - if ( arguments.length < 5 ) { - return factory( options )( collection, initial, fcn ); - } - factory( options, fcn )( collection, initial, done ); -} - - -// EXPORTS // - -module.exports = reduceRightAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 0c666fe..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @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 -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'thisArg': {}, -* 'series': false, -* 'limit': 10 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '1RZ2V', options ) ); - } - if ( hasOwnProp( options, 'thisArg' ) ) { - opts.thisArg = options.thisArg; - } - if ( hasOwnProp( options, 'series' ) ) { - opts.series = options.series; - if ( !isBoolean( opts.series ) ) { - return new TypeError( format( '1RZ2o', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '1RZ3P', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 0c316c5..563c57c 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,44 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-collection": "^0.2.2", - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/assert-is-positive-integer": "^0.2.2", - "@stdlib/constants-float64-pinf": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "debug": "^2.6.9", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/constants-float64-eps": "^0.2.2", - "@stdlib/fs-read-file": "^0.2.2", - "@stdlib/utils-noop": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..69bcdc8 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 8244931..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1095 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( {}, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, next ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - factory( opts, next ); - }; - } -}); - -tape( 'the function returns a function (no options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided a collection (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a collection (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (1 argument)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (2 arguments)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with five arguments', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn() { - var value; - var next; - var acc; - var k; - - acc = arguments[ 0 ]; - value = arguments[ 1 ]; - k = arguments[ 2 ]; - next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( k, i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the returned function supports processing collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements concurrently', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 100, 250, 300 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements sequentially (limit = 1)', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of collection elements which are processed at any one time', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 250, 300, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 250, 100, 300 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var reduceRightAsync; - var arr; - - reduceRightAsync = factory( fcn ); - arr = []; - - reduceRightAsync( arr, 0, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var reduceRightAsync; - var obj; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = []; - obj = {}; - reduceRightAsync( arr, obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - i = 0; - - reduceRightAsync( arr, {}, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, acc ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the returned function does not skip empty elements', function test( t ) { - var reduceRightAsync; - var expected; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index f273a40..0000000 --- a/test/test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof reduceRightAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 1893240..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1035 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a collection', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (no options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, next, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, 0 ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - reduceRightAsync( [ 1, 2, 3 ], 0, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (1 argument)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (2 arguments)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with five arguments', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn() { - var next; - var acc; - var v; - - next = arguments[ 4 ]; - acc = arguments[ 0 ]; - v = arguments[ 1 ]; - - i -= 1; - j += 1; - - t.strictEqual( v, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, v ); - - function onTimeout() { - acc.sum += v; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'by default, the function processes collection elements sequentially', function test( t ) { - var values; - var count; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements concurrently', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 100, 250, 300 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': true - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially (limit = 1)', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var arr; - var ctx; - - arr = [ 3, 2, 1 ]; - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 3, 2, 1 ]; - opts = { - 'series': true - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 250, 100, 300 ]; - opts = { - 'limit': 2 - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var arr = []; - reduceRightAsync( arr, 0, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var arr = []; - var obj = {}; - - reduceRightAsync( arr, obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - arr = [ 3, 2, 1 ]; - i = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, value ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the function does not skip empty elements', function test( t ) { - var expected; - var arr; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, fcn, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 7660838..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,181 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `limit` option which is not a positive integer', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - -5, - 0, - 3.14, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'limit': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `series` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'series': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function accepts any value for the `thisArg` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'thisArg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err, null, 'returns null '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'thisArg': {}, - 'series': false, - 'limit': 10 - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From 7f0360711780588a0e1bb18428db41ee86baf6fd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 21 Sep 2024 21:52:10 +0000 Subject: [PATCH 127/147] Transform error messages --- lib/factory.js | 8 ++++---- lib/validate.js | 8 ++++---- package.json | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 1125052..e107128 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -22,7 +22,7 @@ var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var PINF = require( '@stdlib/constants-float64-pinf' ); var validate = require( './validate.js' ); var limit = require( './limit.js' ); @@ -109,7 +109,7 @@ function factory( options, fcn ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '1RZ3q', f ) ); } if ( opts.series === void 0 && opts.limit === void 0 ) { opts.series = true; @@ -134,10 +134,10 @@ function factory( options, fcn ) { */ function reduceRightAsync( collection, initial, done ) { if ( !isCollection( collection ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a collection. Value: `%s`.', collection ) ); + throw new TypeError( format( '1RZAh', collection ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '1RZ3q', done ) ); } return limit( collection, initial, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index 9ba927e..0c666fe 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,7 +54,7 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '1RZ2V', options ) ); } if ( hasOwnProp( options, 'thisArg' ) ) { opts.thisArg = options.thisArg; @@ -62,13 +62,13 @@ function validate( opts, options ) { if ( hasOwnProp( options, 'series' ) ) { opts.series = options.series; if ( !isBoolean( opts.series ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'series', opts.series ) ); + return new TypeError( format( '1RZ2o', 'series', opts.series ) ); } } if ( hasOwnProp( options, 'limit' ) ) { opts.limit = options.limit; if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'limit', opts.limit ) ); + return new TypeError( format( '1RZ3P', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index 739500e..0c316c5 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-plain-object": "^0.2.2", "@stdlib/assert-is-positive-integer": "^0.2.2", "@stdlib/constants-float64-pinf": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.1", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", "debug": "^2.6.9", From ee60521ee0d93e6966affa292f07ae9481d6170f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 21 Sep 2024 22:21:28 +0000 Subject: [PATCH 128/147] Remove files --- index.d.ts | 410 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5257 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index f6cba5d..0000000 --- a/index.d.ts +++ /dev/null @@ -1,410 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Execution context. - */ - thisArg?: ThisParameterType>; - - /** - * The maximum number of pending invocations at any one time. - */ - limit?: number; - - /** - * Boolean indicating whether to sequentially invoke the reducer function for each `collection` element. If `true`, the function sets `options.limit=1`. Default: true. - */ - series?: boolean; -} - -/** -* Callback function. -*/ -type Nullary = () => void; - -/** -* Callback function. -* -* @param error - encountered error or null -*/ -type Unary = ( error: Error | null ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Binary = ( error: Error | null, accumulator: U ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param next - a callback to be invoked after processing a collection `value` -*/ -type TernaryReducer = ( this: V, accumulator: U, value: T, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuaternaryReducer = ( this: V, accumulator: U, value: T, index: number, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuinaryReducer = ( this: V, accumulator: U, value: T, index: number, collection: Collection, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type Reducer = TernaryReducer | QuaternaryReducer | QuinaryReducer; - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result. -* -* @param collection - input collection -* @param initial - initial value -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( collection: Collection, initial: U, done: Callback ) => void; - -/** -* Interface for `reduceRightAsync`. -*/ -interface ReduceRightAsync { - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, {}, read, done ); - */ - ( collection: Collection, initial: U, options: Options, reducer: Reducer, done: Callback ): void; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, read, done ); - */ - ( collection: Collection, initial: U, reducer: Reducer, done: Callback ): void; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @throws must provide valid options - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var opts = { - * 'series': false - * }; - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( opts, read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( options: Options, reducer: Reducer ): FactoryFunction; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param reducer - function to invoke for each element in a collection - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( reducer: Reducer ): FactoryFunction; -} - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param collection - input collection -* @param initial - initial value -* @param options - function options -* @param options.thisArg - execution context -* @param options.limit - maximum number of pending invocations at any one time -* @param 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 (default: true) -* @param reducer - function to invoke for each element in a collection -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -declare var reduceRightAsync: ReduceRightAsync; - - -// EXPORTS // - -export = reduceRightAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 234a485..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as c}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";function m(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var d=m(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function f(e,m){var f,u,p;if(f={},arguments.length>1){if(u=function(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("1RZ2o","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!c(e.limit))?new TypeError(r("1RZ3P","limit",e.limit)):null):new TypeError(r("1RZ2V",t))}(f,e),u)throw u;p=m}else p=e;if(!t(p))throw new TypeError(r("1RZ3q",p));return void 0===f.series&&void 0===f.limit&&(f.series=!0),f.series?f.limit=1:f.limit||(f.limit=s),function(e,s,n){if(!i(e))throw new TypeError(r("1RZAh",e));if(!t(n))throw new TypeError(r("1RZ3q",n));return function(e,t,i,r,s){var n,o,l,c,m,f;if(c=e.length,d("Collection length: %d",c),0===c)return d("Finished processing a collection."),s(null,t);for(l=c0&&u();function u(){function s(e,i){if(!o){if(e)return o=!0,p(e);d("Accumulator: %s",JSON.stringify(i)),t=i,p()}}d("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function p(e){return e?(d("Encountered an error: %s",e.message),s(e)):(d("Processed %d of %d collection elements.",n+=1,c),m>0?u():n===c?(d("Finished processing a collection."),s(null,t)):void 0)}}(e,s,f,p,(function(e,t){if(e)return n(e);n(null,t)}))}}function u(e,t,i,r,s){if(arguments.length<5)return f(i)(e,t,r);f(i,r)(e,t,s)}e(u,"factory",f);export{u as default,f as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index e11f2cb..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/limit.js","../lib/factory.js","../lib/validate.js","../lib/main.js","../lib/index.js"],"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 logger = require( 'debug' );\n\n\n// VARIABLES //\n\nvar debug = logger( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RZ3q', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '1RZAh', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RZ3q', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '1RZ2V', 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( '1RZ2o', '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( '1RZ3P', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["debug","logger","factory","options","fcn","opts","err","f","arguments","length","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","validate","isFunction","PINF","collection","initial","done","isCollection","acc","count","flg","lim","len","idx","i","next","cb","error","result","clbk","JSON","stringify","call","message","reduceRightAsync","setReadOnly","main"],"mappings":";;81CA2BIA,uDAAQC,CAAQ,4BCoEpB,SAASC,EAASC,EAASC,GAC1B,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAA,EACFG,UAAUC,OAAS,EAAI,CAE3B,GADAH,EChDF,SAAmBD,EAAMF,GACxB,OAAMO,EAAUP,IAGXQ,EAAYR,EAAS,aACzBE,EAAKO,QAAUT,EAAQS,SAEnBD,EAAYR,EAAS,YACzBE,EAAKQ,OAASV,EAAQU,QAChBC,EAAWT,EAAKQ,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUX,EAAKQ,SAGnDF,EAAYR,EAAS,WACzBE,EAAKY,MAAQd,EAAQc,OACfC,EAAmBb,EAAKY,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASX,EAAKY,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASb,GAkBzC,CD4BQgB,CAAUd,EAAMF,GACjBG,EACJ,MAAMA,EAEPC,EAAIH,CACN,MACEG,EAAIJ,EAEL,IAAMiB,EAAYb,GACjB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAUvC,YARqB,IAAhBF,EAAKQ,aAAoC,IAAfR,EAAKY,QACnCZ,EAAKQ,QAAS,GAEVR,EAAKQ,OACTR,EAAKY,MAAQ,EACDZ,EAAKY,QACjBZ,EAAKY,MAAQI,GAed,SAA2BC,EAAYC,EAASC,GAC/C,IAAMC,EAAcH,GACnB,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,IAAMF,EAAYI,GACjB,MAAM,IAAIT,UAAWC,EAAQ,QAASQ,IAEvC,ODhGF,SAAgBF,EAAYI,EAAKrB,EAAMD,EAAKoB,GAC3C,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMR,EAAWb,OACjBT,EAAO,wBAAyB8B,GAEnB,IAARA,EAEJ,OADA9B,EAAO,qCACAwB,EAAM,KAAME,GAYpB,IATCG,EADIC,EAAMzB,EAAKY,MACTa,EAEAzB,EAAKY,MAEZjB,EAAO,wBAAyB6B,GAChC7B,EAAO,0BAA2BI,EAAIK,QAEtCkB,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVE,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKR,EAAL,CAIA,GAAKO,EAEJ,OADAP,GAAM,EACCS,EAAMF,GAEdnC,EAAO,kBAAmBsC,KAAKC,UAAWH,IAC1CV,EAAMU,EACNC,GAPC,CAQD,CA5BDrC,EAAO,6BADP+B,GAAO,EACmCO,KAAKC,UAAWjB,EAAYS,KAClD,IAAf3B,EAAIK,OACRL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOG,GACtB,IAAf9B,EAAIK,OACfL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKG,GAErD9B,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKT,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJnC,EAAO,2BAA4BmC,EAAMM,SAClCjB,EAAMW,KAGdnC,EAAO,0CADP2B,GAAS,EACgDG,GACpDC,EAAM,EACHE,IAEHN,IAAUG,GACd9B,EAAO,qCACAwB,EAAM,KAAME,SAFpB,EAIA,CACF,CCKST,CAAOK,EAAYC,EAASlB,EAAME,GAUzC,SAAe4B,EAAOT,GACrB,GAAKS,EACJ,OAAOX,EAAMW,GAEdX,EAAM,KAAME,EACZ,GACD,CACF,CE1EA,SAASgB,EAAkBpB,EAAYC,EAASpB,EAASC,EAAKoB,GAC7D,GAAKhB,UAAUC,OAAS,EACvB,OAAOP,EAASC,EAATD,CAAoBoB,EAAYC,EAASnB,GAEjDF,EAASC,EAASC,EAAlBF,CAAyBoB,EAAYC,EAASC,EAC/C,CClBAmB,EAAAC,EAAA,UAAA1C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 69bcdc8..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 1b2ac2fa8ac95b1846ebcedb1dd903bc6a66ab9f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 21 Sep 2024 22:21:40 +0000 Subject: [PATCH 129/147] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 245 -- CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.factory.js | 73 - benchmark/benchmark.js | 160 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 224 - docs/types/test.ts | 166 - examples/index.js | 55 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 164 - lib/index.js | 77 - lib/limit.js | 142 - lib/main.js | 95 - lib/validate.js | 80 - package.json | 65 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 1095 ----- test/test.js | 38 - test/test.main.js | 1035 ----- test/test.validate.js | 181 - 49 files changed, 4873 insertions(+), 7210 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/limit.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1e08946..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 5358060..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index fa37f2d..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '37 1 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -460,7 +457,7 @@ reduceRightAsync( files, acc, read, done ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -531,11 +528,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right +[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right/tree/esm -[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce +[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index b155fd2..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var reduceRightAsync; - var arr; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - reduceRightAsync = factory( onItem ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - var acc; - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index af5c346..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var reduceRightAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=false', function benchmark( b ) { - var opts; - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'series': false - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var arr; - var len; - var acc; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'limit': 3 - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b8adcd2..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right" -%% click B href "https://github.com/stdlib-js/utils-async-reduce-right/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-reduce-right/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-reduce-right/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-reduce-right/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right -[production-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-async-reduce-right/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-async-reduce-right/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-async-reduce-right/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 47a072e..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import reduceRightAsync from '../docs/types/index'; -export = reduceRightAsync; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 530ca4d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var c=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var x=c(function(U,O){ -var R=require('@stdlib/assert-is-plain-object/dist'),h=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,k=require('@stdlib/assert-is-positive-integer/dist').isPrimitive,d=require('@stdlib/error-tools-fmtprodmsg/dist');function I(e,r){return R(r)?(h(r,"thisArg")&&(e.thisArg=r.thisArg),h(r,"series")&&(e.series=r.series,!j(e.series))?new TypeError(d('1RZ2o',"series",e.series)):h(r,"limit")&&(e.limit=r.limit,!k(e.limit))?new TypeError(d('1RZ3P',"limit",e.limit)):null):new TypeError(d('1RZ2V',r));}O.exports=I -});var P=c(function(W,E){ -var J=require("debug"),a=J("reduce-right-async:limit");function L(e,r,i,t,s){var f,m,v,n,u,g;if(n=e.length,a("Collection length: %d",n),n===0)return a("Finished processing a collection."),s(null,r);for(n0&&o();function o(){u-=1,a("Collection element %d: %s.",u,JSON.stringify(e[u])),t.length===3?t.call(i.thisArg,r,e[u],l):t.length===4?t.call(i.thisArg,r,e[u],u,l):t.call(i.thisArg,r,e[u],u,e,l);function l(w,A){if(!m){if(w)return m=!0,b(w);a("Accumulator: %s",JSON.stringify(A)),r=A,b()}}}function b(l){if(l)return a("Encountered an error: %s",l.message),s(l);if(f+=1,a("Processed %d of %d collection elements.",f,n),u>0)return o();if(f===n)return a("Finished processing a collection."),s(null,r)}}E.exports=L -});var q=c(function(X,F){ -var T=require('@stdlib/assert-is-function/dist'),S=require('@stdlib/assert-is-collection/dist'),y=require('@stdlib/error-tools-fmtprodmsg/dist'),B=require('@stdlib/constants-float64-pinf/dist'),z=x(),D=P();function G(e,r){var i,t,s;if(i={},arguments.length>1){if(t=z(i,e),t)throw t;s=r}else s=e;if(!T(s))throw new TypeError(y('1RZ3q',s));return i.series===void 0&&i.limit===void 0&&(i.series=!0),i.series?i.limit=1:i.limit||(i.limit=B),f;function f(m,v,n){if(!S(m))throw new TypeError(y('1RZAh',m));if(!T(n))throw new TypeError(y('1RZ3q',n));return D(m,v,i,s,u);function u(g,o){if(g)return n(g);n(null,o)}}}F.exports=G -});var N=c(function(Y,C){ -var p=q();function H(e,r,i,t,s){if(arguments.length<5)return p(i)(e,r,t);p(i,t)(e,r,s)}C.exports=H -});var K=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),V=N(),M=q();K(V,"factory",M);module.exports=V; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index acb9d67..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/limit.js", "../lib/factory.js", "../lib/main.js", "../lib/index.js"], - "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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\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 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 to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\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 === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, 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 ( !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, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\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* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nmodule.exports = reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' );\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, 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"], - "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,0BAA2B,EAkB/C,SAASE,EAAOC,EAAYC,EAAKC,EAAMC,EAAKC,EAAO,CAClD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMR,EAAW,OACjBF,EAAO,wBAAyBU,CAAI,EAE/BA,IAAQ,EACZ,OAAAV,EAAO,mCAAoC,EACpCM,EAAM,KAAMH,CAAI,EAYxB,IAVKO,EAAMN,EAAK,MACfK,EAAMC,EAEND,EAAML,EAAK,MAEZJ,EAAO,wBAAyBS,CAAI,EACpCT,EAAO,0BAA2BK,EAAI,MAAO,EAE7CE,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVE,EAAK,EAQP,SAASA,GAAO,CACfF,GAAO,EACPX,EAAO,6BAA8BW,EAAK,KAAK,UAAWT,EAAYS,CAAI,CAAE,CAAE,EACzEN,EAAI,SAAW,EACnBA,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGG,CAAG,EACxCT,EAAI,SAAW,EAC1BA,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGA,EAAKG,CAAG,EAExDT,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGA,EAAKT,EAAYY,CAAG,EAUrE,SAASA,EAAIC,EAAOC,EAAS,CAC5B,GAAK,CAAAR,EAIL,IAAKO,EACJ,OAAAP,EAAM,GACCS,EAAMF,CAAM,EAEpBf,EAAO,kBAAmB,KAAK,UAAWgB,CAAO,CAAE,EACnDb,EAAMa,EACNC,EAAK,EACN,CACD,CASA,SAASA,EAAMF,EAAQ,CACtB,GAAKA,EACJ,OAAAf,EAAO,2BAA4Be,EAAM,OAAQ,EAC1CT,EAAMS,CAAM,EAIpB,GAFAR,GAAS,EACTP,EAAO,0CAA2CO,EAAOG,CAAI,EACxDC,EAAM,EACV,OAAOE,EAAK,EAEb,GAAKN,IAAUG,EACd,OAAAV,EAAO,mCAAoC,EACpCM,EAAM,KAAMH,CAAI,CAEzB,CACD,CAKAL,EAAO,QAAUG,IC7IjB,IAAAiB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,gCAAiC,EACjDC,EAAW,IACXC,EAAQ,IAoEZ,SAASC,EAASC,EAASC,EAAM,CAChC,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,CAACP,EAAYW,CAAE,EACnB,MAAM,IAAI,UAAWT,EAAQ,mEAAoES,CAAE,CAAE,EAEtG,OAAKF,EAAK,SAAW,QAAUA,EAAK,QAAU,SAC7CA,EAAK,OAAS,IAEVA,EAAK,OACTA,EAAK,MAAQ,EACDA,EAAK,QACjBA,EAAK,MAAQN,GAEPS,EAaP,SAASA,EAAkBC,EAAYC,EAASC,EAAO,CACtD,GAAK,CAACd,EAAcY,CAAW,EAC9B,MAAM,IAAI,UAAWX,EAAQ,sEAAuEW,CAAW,CAAE,EAElH,GAAK,CAACb,EAAYe,CAAK,EACtB,MAAM,IAAI,UAAWb,EAAQ,mEAAoEa,CAAK,CAAE,EAEzG,OAAOV,EAAOQ,EAAYC,EAASL,EAAME,EAAGK,CAAK,EAUjD,SAASA,EAAMC,EAAOC,EAAM,CAC3B,GAAKD,EACJ,OAAOF,EAAME,CAAM,EAEpBF,EAAM,KAAMG,CAAI,CACjB,CACD,CACD,CAKAnB,EAAO,QAAUO,ICnKjB,IAAAa,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,IA8Dd,SAASC,EAAkBC,EAAYC,EAASC,EAASC,EAAKC,EAAO,CACpE,GAAK,UAAU,OAAS,EACvB,OAAON,EAASI,CAAQ,EAAGF,EAAYC,EAASE,CAAI,EAErDL,EAASI,EAASC,CAAI,EAAGH,EAAYC,EAASG,CAAK,CACpD,CAKAP,EAAO,QAAUE,IC9BjB,IAAIM,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "isPositiveInteger", "format", "validate", "opts", "options", "require_limit", "__commonJSMin", "exports", "module", "logger", "debug", "limit", "collection", "acc", "opts", "fcn", "done", "count", "flg", "lim", "len", "idx", "i", "next", "cb", "error", "result", "clbk", "require_factory", "__commonJSMin", "exports", "module", "isFunction", "isCollection", "format", "PINF", "validate", "limit", "factory", "options", "fcn", "opts", "err", "f", "reduceRightAsync", "collection", "initial", "done", "clbk", "error", "acc", "require_main", "__commonJSMin", "exports", "module", "factory", "reduceRightAsync", "collection", "initial", "options", "fcn", "done", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 078b453..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,224 +0,0 @@ - -{{alias}}( collection, initial, [options,] reducer, done ) - Applies a function against an accumulator and each element in a collection - and returns the accumulated result, iterating from right to left. - - When invoked, `reducer` is provided a maximum of five arguments: - - - accumulator: accumulated value. - - value: collection value. - - index: collection index. - - collection: the input collection. - - next: a callback to be invoked after processing a collection `value`. - - The actual number of provided arguments depends on function length. If - `reducer` accepts three arguments, `reducer` is provided: - - - accumulator - - value - - next - - If `reducer` accepts four arguments, `reducer` is provided: - - - accumulator - - value - - index - - next - - For every other `reducer` signature, `reducer` is provided all five - arguments. - - The `next` callback accepts two arguments: - - - error: error argument. - - accumulator: accumulated value. - - If a provided function calls the `next` callback with a truthy `error` - argument, the function suspends execution and immediately calls the `done` - callback for subsequent `error` handling. - - Execution is *not* guaranteed to be asynchronous. To guarantee asynchrony, - 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`). - - The function does not support dynamic collection resizing. - - If provided an empty collection, the function invokes the `done` callback - with the `initial` value as the second argument. - - The function does not skip `undefined` elements. - - When processing collection elements concurrently, *beware* of race - conditions when updating an accumulator. This is especially true when an - accumulator is a primitive (e.g., a number). In general, prefer object - accumulators. - - Parameters - ---------- - collection: Array|TypedArray|Object - Input collection over which to iterate. If provided an object, the - object must be array-like (excluding strings and functions). - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - reducer: Function - The function to invoke for each element in a collection. - - done: Function - A callback invoked either upon processing all collection elements or - upon encountering an error. - - Examples - -------- - // Basic usage: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, fcn, done ) - 3000 - 2500 - 1000 - 6500 - - // Limit number of concurrent invocations: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'limit': 2 }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 2500 - 3000 - 1000 - 6500 - - // Process concurrently: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'series': false }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 1000 - 2500 - 3000 - 6500 - - -{{alias}}.factory( [options,] fcn ) - Returns a function which applies a function against an accumulator and each - element in a collection and returns the accumulated result, iterating from - right to left. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - fcn: Function - The function to invoke for each element in a collection. - - Returns - ------- - out: Function - A function which invokes a function for each element in a collection. - - Examples - -------- - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > var opts = { 'series': false }; - > var f = {{alias}}.factory( opts, fcn ); - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > f( arr, acc, done ) - 1000 - 2500 - 3000 - 6500 - > acc = { 'sum': 0 }; - > arr = [ 1000, 1500, 2000 ]; - > f( arr, acc, done ) - 1000 - 1500 - 2000 - 4500 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0455864..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,166 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unsafe-assignment */ - -import reduceRightAsync = require( './index' ); - -const reducer = ( acc: any, value: number, index: number, next: Function ) => { - acc.sum += value; - if ( index === void 0 ) { - throw new Error( '`index` is missing.' ); - } - next( null, acc ); -}; - -const done = ( error: Error | null, acc: any ) => { - if ( error ) { - throw error; - } - if ( acc === void 0 ) { - throw new Error( '`acc` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( 2, acc, reducer, done ); // $ExpectError - reduceRightAsync( false, acc, reducer, done ); // $ExpectError - reduceRightAsync( true, acc, reducer, done ); // $ExpectError - reduceRightAsync( {}, acc, reducer, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a predicate argument which is not a predicate function... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 2, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, false, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, true, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 'abc', done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, [], done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a done callback argument which is not a function having a supported signature... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 2 ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, false ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, true ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 'abc' ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, {} ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, [] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const acc = { 'sum': 0 }; - reduceRightAsync(); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, reducer, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - reduceRightAsync.factory( reducer ); // $ExpectType FactoryFunction - reduceRightAsync.factory( { 'series': true }, reducer ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - reduceRightAsync.factory( [], reducer ); // $ExpectError - reduceRightAsync.factory( 123, reducer ); // $ExpectError - reduceRightAsync.factory( 'abc', reducer ); // $ExpectError - reduceRightAsync.factory( false, reducer ); // $ExpectError - reduceRightAsync.factory( true, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not a predicate function... -{ - reduceRightAsync.factory( {} ); // $ExpectError - reduceRightAsync.factory( true ); // $ExpectError - reduceRightAsync.factory( false ); // $ExpectError - reduceRightAsync.factory( {}, 123 ); // $ExpectError - reduceRightAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1( 12, acc, done ); // $ExpectError - fcn1( true, acc, done ); // $ExpectError - fcn1( false, acc, done ); // $ExpectError - fcn1( {}, acc, done ); // $ExpectError - - fcn1( [ 3000, 2500, 1000 ], acc, 12 ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, true ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, false ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, '5' ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, {} ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, [] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1(); // $ExpectError - fcn1( [ 3000, 2500, 1000 ] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - reduceRightAsync.factory( { 'limit': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': true }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': false }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - reduceRightAsync.factory( { 'series': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': 12 }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - reduceRightAsync.factory(); // $ExpectError - reduceRightAsync.factory( {}, reducer, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index dd64345..0000000 --- a/examples/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var resolve = require( 'path' ).resolve; -var readFile = require( '@stdlib/fs-read-file' ); -var reduceRightAsync = require( './../lib' ); - -var files = [ - resolve( __dirname, '..', 'package.json' ), - resolve( __dirname, '..', 'README.md' ) -]; - -function done( error, acc ) { - if ( error ) { - throw error; - } - console.log( acc.count ); -} - -function read( acc, file, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( file, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( null, acc ); - } - acc.count += 1; - next( null, acc ); - } -} - -var acc = { - 'count': 0 -}; -reduceRightAsync( files, acc, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 28e0a36..f6cba5d 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..234a485 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as c}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";function m(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var d=m(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function f(e,m){var f,u,p;if(f={},arguments.length>1){if(u=function(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("1RZ2o","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!c(e.limit))?new TypeError(r("1RZ3P","limit",e.limit)):null):new TypeError(r("1RZ2V",t))}(f,e),u)throw u;p=m}else p=e;if(!t(p))throw new TypeError(r("1RZ3q",p));return void 0===f.series&&void 0===f.limit&&(f.series=!0),f.series?f.limit=1:f.limit||(f.limit=s),function(e,s,n){if(!i(e))throw new TypeError(r("1RZAh",e));if(!t(n))throw new TypeError(r("1RZ3q",n));return function(e,t,i,r,s){var n,o,l,c,m,f;if(c=e.length,d("Collection length: %d",c),0===c)return d("Finished processing a collection."),s(null,t);for(l=c0&&u();function u(){function s(e,i){if(!o){if(e)return o=!0,p(e);d("Accumulator: %s",JSON.stringify(i)),t=i,p()}}d("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function p(e){return e?(d("Encountered an error: %s",e.message),s(e)):(d("Processed %d of %d collection elements.",n+=1,c),m>0?u():n===c?(d("Finished processing a collection."),s(null,t)):void 0)}}(e,s,f,p,(function(e,t){if(e)return n(e);n(null,t)}))}}function u(e,t,i,r,s){if(arguments.length<5)return f(i)(e,t,r);f(i,r)(e,t,s)}e(u,"factory",f);export{u as default,f as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..e11f2cb --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/limit.js","../lib/factory.js","../lib/validate.js","../lib/main.js","../lib/index.js"],"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 logger = require( 'debug' );\n\n\n// VARIABLES //\n\nvar debug = logger( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RZ3q', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '1RZAh', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RZ3q', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '1RZ2V', 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( '1RZ2o', '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( '1RZ3P', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["debug","logger","factory","options","fcn","opts","err","f","arguments","length","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","validate","isFunction","PINF","collection","initial","done","isCollection","acc","count","flg","lim","len","idx","i","next","cb","error","result","clbk","JSON","stringify","call","message","reduceRightAsync","setReadOnly","main"],"mappings":";;81CA2BIA,uDAAQC,CAAQ,4BCoEpB,SAASC,EAASC,EAASC,GAC1B,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAA,EACFG,UAAUC,OAAS,EAAI,CAE3B,GADAH,EChDF,SAAmBD,EAAMF,GACxB,OAAMO,EAAUP,IAGXQ,EAAYR,EAAS,aACzBE,EAAKO,QAAUT,EAAQS,SAEnBD,EAAYR,EAAS,YACzBE,EAAKQ,OAASV,EAAQU,QAChBC,EAAWT,EAAKQ,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUX,EAAKQ,SAGnDF,EAAYR,EAAS,WACzBE,EAAKY,MAAQd,EAAQc,OACfC,EAAmBb,EAAKY,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASX,EAAKY,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASb,GAkBzC,CD4BQgB,CAAUd,EAAMF,GACjBG,EACJ,MAAMA,EAEPC,EAAIH,CACN,MACEG,EAAIJ,EAEL,IAAMiB,EAAYb,GACjB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAUvC,YARqB,IAAhBF,EAAKQ,aAAoC,IAAfR,EAAKY,QACnCZ,EAAKQ,QAAS,GAEVR,EAAKQ,OACTR,EAAKY,MAAQ,EACDZ,EAAKY,QACjBZ,EAAKY,MAAQI,GAed,SAA2BC,EAAYC,EAASC,GAC/C,IAAMC,EAAcH,GACnB,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,IAAMF,EAAYI,GACjB,MAAM,IAAIT,UAAWC,EAAQ,QAASQ,IAEvC,ODhGF,SAAgBF,EAAYI,EAAKrB,EAAMD,EAAKoB,GAC3C,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMR,EAAWb,OACjBT,EAAO,wBAAyB8B,GAEnB,IAARA,EAEJ,OADA9B,EAAO,qCACAwB,EAAM,KAAME,GAYpB,IATCG,EADIC,EAAMzB,EAAKY,MACTa,EAEAzB,EAAKY,MAEZjB,EAAO,wBAAyB6B,GAChC7B,EAAO,0BAA2BI,EAAIK,QAEtCkB,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVE,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKR,EAAL,CAIA,GAAKO,EAEJ,OADAP,GAAM,EACCS,EAAMF,GAEdnC,EAAO,kBAAmBsC,KAAKC,UAAWH,IAC1CV,EAAMU,EACNC,GAPC,CAQD,CA5BDrC,EAAO,6BADP+B,GAAO,EACmCO,KAAKC,UAAWjB,EAAYS,KAClD,IAAf3B,EAAIK,OACRL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOG,GACtB,IAAf9B,EAAIK,OACfL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKG,GAErD9B,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKT,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJnC,EAAO,2BAA4BmC,EAAMM,SAClCjB,EAAMW,KAGdnC,EAAO,0CADP2B,GAAS,EACgDG,GACpDC,EAAM,EACHE,IAEHN,IAAUG,GACd9B,EAAO,qCACAwB,EAAM,KAAME,SAFpB,EAIA,CACF,CCKST,CAAOK,EAAYC,EAASlB,EAAME,GAUzC,SAAe4B,EAAOT,GACrB,GAAKS,EACJ,OAAOX,EAAMW,GAEdX,EAAM,KAAME,EACZ,GACD,CACF,CE1EA,SAASgB,EAAkBpB,EAAYC,EAASpB,EAASC,EAAKoB,GAC7D,GAAKhB,UAAUC,OAAS,EACvB,OAAOP,EAASC,EAATD,CAAoBoB,EAAYC,EAASnB,GAEjDF,EAASC,EAASC,EAAlBF,CAAyBoB,EAAYC,EAASC,EAC/C,CClBAmB,EAAAC,EAAA,UAAA1C"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index e107128..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,164 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var validate = require( './validate.js' ); -var limit = require( './limit.js' ); - - -// MAIN // - -/** -* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} last argument must be a function -* @returns {Function} function which invokes the provided function once for each element in a collection -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error, data ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var opts = { -* 'series': false -* }; -* -* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: -* var reduceRightAsync = factory( opts, read ); -* -* // Create a collection over which to iterate: -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* // Define a callback which handles errors: -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* // Run `read` for each element in `files`: -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, done ); -*/ -function factory( options, fcn ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = fcn; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '1RZ3q', f ) ); - } - if ( opts.series === void 0 && opts.limit === void 0 ) { - opts.series = true; - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return reduceRightAsync; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * @private - * @param {Collection} collection - input collection - * @param {*} initial - initial value - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be a collection - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function reduceRightAsync( collection, initial, done ) { - if ( !isCollection( collection ) ) { - throw new TypeError( format( '1RZAh', collection ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '1RZ3q', done ) ); - } - return limit( collection, initial, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {*} [acc] - accumulated value - * @returns {void} - */ - function clbk( error, acc ) { - if ( error ) { - return done( error ); - } - done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ae657ff..0000000 --- a/lib/index.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* @module @stdlib/utils-async-reduce-right -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' ); -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/limit.js b/lib/limit.js deleted file mode 100644 index cdb60af..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); - - -// VARIABLES // - -var debug = logger( 'reduce-right-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each element in a collection, limiting the number of concurrently pending functions and iterating from right to left. -* -* @private -* @param {Collection} collection - input collection -* @param {*} acc - initial value -* @param {Options} opts - function options -* @param {*} [opts.thisArg] - execution context -* @param {PositiveInteger} [opts.limit] - maximum number of pending function invocations -* @param {Function} fcn - function to invoke -* @param {Callback} done - function to invoke upon completion or upon encountering an error -* @returns {void} -*/ -function limit( collection, acc, opts, fcn, done ) { - var count; - var flg; - var lim; - var len; - var idx; - var i; - - len = collection.length; - debug( 'Collection length: %d', len ); - - if ( len === 0 ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - count = 0; - idx = len; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all collection elements... - if ( idx > 0 ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next element in a collection. - * - * @private - */ - function next() { - idx -= 1; - debug( 'Collection element %d: %s.', idx, JSON.stringify( collection[ idx ] ) ); - if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], cb ); - } else if ( fcn.length === 4 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, cb ); - } else { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len - } - /** - * Callback invoked once a provided function finishes processing a collection element. - * - * @private - * @param {*} [error] - error - * @param {*} [result] - accumulation result - * @returns {void} - */ - function cb( error, result ) { - if ( flg ) { - // Prevent further processing of collection elements: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Accumulator: %s', JSON.stringify( result ) ); - acc = result; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next collection element. - * - * @private - * @param {*} [error] - error - * @returns {void} - */ - function clbk( error ) { - if ( error ) { - debug( 'Encountered an error: %s', error.message ); - return done( error ); - } - count += 1; - debug( 'Processed %d of %d collection elements.', count, len ); - if ( idx > 0 ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index c8b0d0f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param {Collection} collection - input collection -* @param {*} initial - initial value -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} second-to-last argument must be a function -* @throws {TypeError} last argument must be a function -* @returns {void} -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -function reduceRightAsync( collection, initial, options, fcn, done ) { - if ( arguments.length < 5 ) { - return factory( options )( collection, initial, fcn ); - } - factory( options, fcn )( collection, initial, done ); -} - - -// EXPORTS // - -module.exports = reduceRightAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 0c666fe..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @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 -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'thisArg': {}, -* 'series': false, -* 'limit': 10 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '1RZ2V', options ) ); - } - if ( hasOwnProp( options, 'thisArg' ) ) { - opts.thisArg = options.thisArg; - } - if ( hasOwnProp( options, 'series' ) ) { - opts.series = options.series; - if ( !isBoolean( opts.series ) ) { - return new TypeError( format( '1RZ2o', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '1RZ3P', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 0c316c5..563c57c 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,44 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-collection": "^0.2.2", - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/assert-is-positive-integer": "^0.2.2", - "@stdlib/constants-float64-pinf": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "debug": "^2.6.9", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/constants-float64-eps": "^0.2.2", - "@stdlib/fs-read-file": "^0.2.2", - "@stdlib/utils-noop": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..69bcdc8 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 8244931..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1095 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( {}, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, next ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - factory( opts, next ); - }; - } -}); - -tape( 'the function returns a function (no options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided a collection (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a collection (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (1 argument)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (2 arguments)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with five arguments', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn() { - var value; - var next; - var acc; - var k; - - acc = arguments[ 0 ]; - value = arguments[ 1 ]; - k = arguments[ 2 ]; - next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( k, i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the returned function supports processing collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements concurrently', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 100, 250, 300 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements sequentially (limit = 1)', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of collection elements which are processed at any one time', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 250, 300, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 250, 100, 300 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var reduceRightAsync; - var arr; - - reduceRightAsync = factory( fcn ); - arr = []; - - reduceRightAsync( arr, 0, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var reduceRightAsync; - var obj; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = []; - obj = {}; - reduceRightAsync( arr, obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - i = 0; - - reduceRightAsync( arr, {}, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, acc ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the returned function does not skip empty elements', function test( t ) { - var reduceRightAsync; - var expected; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index f273a40..0000000 --- a/test/test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof reduceRightAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 1893240..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1035 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a collection', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (no options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, next, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, 0 ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - reduceRightAsync( [ 1, 2, 3 ], 0, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (1 argument)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (2 arguments)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with five arguments', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn() { - var next; - var acc; - var v; - - next = arguments[ 4 ]; - acc = arguments[ 0 ]; - v = arguments[ 1 ]; - - i -= 1; - j += 1; - - t.strictEqual( v, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, v ); - - function onTimeout() { - acc.sum += v; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'by default, the function processes collection elements sequentially', function test( t ) { - var values; - var count; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements concurrently', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 100, 250, 300 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': true - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially (limit = 1)', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var arr; - var ctx; - - arr = [ 3, 2, 1 ]; - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 3, 2, 1 ]; - opts = { - 'series': true - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 250, 100, 300 ]; - opts = { - 'limit': 2 - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var arr = []; - reduceRightAsync( arr, 0, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var arr = []; - var obj = {}; - - reduceRightAsync( arr, obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - arr = [ 3, 2, 1 ]; - i = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, value ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the function does not skip empty elements', function test( t ) { - var expected; - var arr; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, fcn, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 7660838..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,181 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `limit` option which is not a positive integer', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - -5, - 0, - 3.14, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'limit': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `series` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'series': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function accepts any value for the `thisArg` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'thisArg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err, null, 'returns null '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'thisArg': {}, - 'series': false, - 'limit': 10 - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From 6be51045f03bf597b2266b37a73c419653553292 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 04:40:18 +0000 Subject: [PATCH 130/147] Transform error messages --- lib/factory.js | 8 ++++---- lib/validate.js | 8 ++++---- package.json | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 1125052..e107128 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -22,7 +22,7 @@ var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var PINF = require( '@stdlib/constants-float64-pinf' ); var validate = require( './validate.js' ); var limit = require( './limit.js' ); @@ -109,7 +109,7 @@ function factory( options, fcn ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '1RZ3q', f ) ); } if ( opts.series === void 0 && opts.limit === void 0 ) { opts.series = true; @@ -134,10 +134,10 @@ function factory( options, fcn ) { */ function reduceRightAsync( collection, initial, done ) { if ( !isCollection( collection ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a collection. Value: `%s`.', collection ) ); + throw new TypeError( format( '1RZAh', collection ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '1RZ3q', done ) ); } return limit( collection, initial, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index 9ba927e..0c666fe 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,7 +54,7 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '1RZ2V', options ) ); } if ( hasOwnProp( options, 'thisArg' ) ) { opts.thisArg = options.thisArg; @@ -62,13 +62,13 @@ function validate( opts, options ) { if ( hasOwnProp( options, 'series' ) ) { opts.series = options.series; if ( !isBoolean( opts.series ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'series', opts.series ) ); + return new TypeError( format( '1RZ2o', 'series', opts.series ) ); } } if ( hasOwnProp( options, 'limit' ) ) { opts.limit = options.limit; if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'limit', opts.limit ) ); + return new TypeError( format( '1RZ3P', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index 739500e..0c316c5 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-plain-object": "^0.2.2", "@stdlib/assert-is-positive-integer": "^0.2.2", "@stdlib/constants-float64-pinf": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.1", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", "debug": "^2.6.9", From e76e73c5dd512a7dd951bd51bac0f85f52fa493b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 08:22:44 +0000 Subject: [PATCH 131/147] Remove files --- index.d.ts | 410 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5257 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index f6cba5d..0000000 --- a/index.d.ts +++ /dev/null @@ -1,410 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Execution context. - */ - thisArg?: ThisParameterType>; - - /** - * The maximum number of pending invocations at any one time. - */ - limit?: number; - - /** - * Boolean indicating whether to sequentially invoke the reducer function for each `collection` element. If `true`, the function sets `options.limit=1`. Default: true. - */ - series?: boolean; -} - -/** -* Callback function. -*/ -type Nullary = () => void; - -/** -* Callback function. -* -* @param error - encountered error or null -*/ -type Unary = ( error: Error | null ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Binary = ( error: Error | null, accumulator: U ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param next - a callback to be invoked after processing a collection `value` -*/ -type TernaryReducer = ( this: V, accumulator: U, value: T, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuaternaryReducer = ( this: V, accumulator: U, value: T, index: number, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuinaryReducer = ( this: V, accumulator: U, value: T, index: number, collection: Collection, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type Reducer = TernaryReducer | QuaternaryReducer | QuinaryReducer; - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result. -* -* @param collection - input collection -* @param initial - initial value -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( collection: Collection, initial: U, done: Callback ) => void; - -/** -* Interface for `reduceRightAsync`. -*/ -interface ReduceRightAsync { - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, {}, read, done ); - */ - ( collection: Collection, initial: U, options: Options, reducer: Reducer, done: Callback ): void; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, read, done ); - */ - ( collection: Collection, initial: U, reducer: Reducer, done: Callback ): void; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @throws must provide valid options - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var opts = { - * 'series': false - * }; - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( opts, read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( options: Options, reducer: Reducer ): FactoryFunction; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param reducer - function to invoke for each element in a collection - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( reducer: Reducer ): FactoryFunction; -} - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param collection - input collection -* @param initial - initial value -* @param options - function options -* @param options.thisArg - execution context -* @param options.limit - maximum number of pending invocations at any one time -* @param 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 (default: true) -* @param reducer - function to invoke for each element in a collection -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -declare var reduceRightAsync: ReduceRightAsync; - - -// EXPORTS // - -export = reduceRightAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 234a485..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as c}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";function m(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var d=m(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function f(e,m){var f,u,p;if(f={},arguments.length>1){if(u=function(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("1RZ2o","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!c(e.limit))?new TypeError(r("1RZ3P","limit",e.limit)):null):new TypeError(r("1RZ2V",t))}(f,e),u)throw u;p=m}else p=e;if(!t(p))throw new TypeError(r("1RZ3q",p));return void 0===f.series&&void 0===f.limit&&(f.series=!0),f.series?f.limit=1:f.limit||(f.limit=s),function(e,s,n){if(!i(e))throw new TypeError(r("1RZAh",e));if(!t(n))throw new TypeError(r("1RZ3q",n));return function(e,t,i,r,s){var n,o,l,c,m,f;if(c=e.length,d("Collection length: %d",c),0===c)return d("Finished processing a collection."),s(null,t);for(l=c0&&u();function u(){function s(e,i){if(!o){if(e)return o=!0,p(e);d("Accumulator: %s",JSON.stringify(i)),t=i,p()}}d("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function p(e){return e?(d("Encountered an error: %s",e.message),s(e)):(d("Processed %d of %d collection elements.",n+=1,c),m>0?u():n===c?(d("Finished processing a collection."),s(null,t)):void 0)}}(e,s,f,p,(function(e,t){if(e)return n(e);n(null,t)}))}}function u(e,t,i,r,s){if(arguments.length<5)return f(i)(e,t,r);f(i,r)(e,t,s)}e(u,"factory",f);export{u as default,f as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index e11f2cb..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/limit.js","../lib/factory.js","../lib/validate.js","../lib/main.js","../lib/index.js"],"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 logger = require( 'debug' );\n\n\n// VARIABLES //\n\nvar debug = logger( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RZ3q', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '1RZAh', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RZ3q', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '1RZ2V', 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( '1RZ2o', '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( '1RZ3P', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["debug","logger","factory","options","fcn","opts","err","f","arguments","length","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","validate","isFunction","PINF","collection","initial","done","isCollection","acc","count","flg","lim","len","idx","i","next","cb","error","result","clbk","JSON","stringify","call","message","reduceRightAsync","setReadOnly","main"],"mappings":";;81CA2BIA,uDAAQC,CAAQ,4BCoEpB,SAASC,EAASC,EAASC,GAC1B,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAA,EACFG,UAAUC,OAAS,EAAI,CAE3B,GADAH,EChDF,SAAmBD,EAAMF,GACxB,OAAMO,EAAUP,IAGXQ,EAAYR,EAAS,aACzBE,EAAKO,QAAUT,EAAQS,SAEnBD,EAAYR,EAAS,YACzBE,EAAKQ,OAASV,EAAQU,QAChBC,EAAWT,EAAKQ,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUX,EAAKQ,SAGnDF,EAAYR,EAAS,WACzBE,EAAKY,MAAQd,EAAQc,OACfC,EAAmBb,EAAKY,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASX,EAAKY,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASb,GAkBzC,CD4BQgB,CAAUd,EAAMF,GACjBG,EACJ,MAAMA,EAEPC,EAAIH,CACN,MACEG,EAAIJ,EAEL,IAAMiB,EAAYb,GACjB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAUvC,YARqB,IAAhBF,EAAKQ,aAAoC,IAAfR,EAAKY,QACnCZ,EAAKQ,QAAS,GAEVR,EAAKQ,OACTR,EAAKY,MAAQ,EACDZ,EAAKY,QACjBZ,EAAKY,MAAQI,GAed,SAA2BC,EAAYC,EAASC,GAC/C,IAAMC,EAAcH,GACnB,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,IAAMF,EAAYI,GACjB,MAAM,IAAIT,UAAWC,EAAQ,QAASQ,IAEvC,ODhGF,SAAgBF,EAAYI,EAAKrB,EAAMD,EAAKoB,GAC3C,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMR,EAAWb,OACjBT,EAAO,wBAAyB8B,GAEnB,IAARA,EAEJ,OADA9B,EAAO,qCACAwB,EAAM,KAAME,GAYpB,IATCG,EADIC,EAAMzB,EAAKY,MACTa,EAEAzB,EAAKY,MAEZjB,EAAO,wBAAyB6B,GAChC7B,EAAO,0BAA2BI,EAAIK,QAEtCkB,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVE,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKR,EAAL,CAIA,GAAKO,EAEJ,OADAP,GAAM,EACCS,EAAMF,GAEdnC,EAAO,kBAAmBsC,KAAKC,UAAWH,IAC1CV,EAAMU,EACNC,GAPC,CAQD,CA5BDrC,EAAO,6BADP+B,GAAO,EACmCO,KAAKC,UAAWjB,EAAYS,KAClD,IAAf3B,EAAIK,OACRL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOG,GACtB,IAAf9B,EAAIK,OACfL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKG,GAErD9B,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKT,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJnC,EAAO,2BAA4BmC,EAAMM,SAClCjB,EAAMW,KAGdnC,EAAO,0CADP2B,GAAS,EACgDG,GACpDC,EAAM,EACHE,IAEHN,IAAUG,GACd9B,EAAO,qCACAwB,EAAM,KAAME,SAFpB,EAIA,CACF,CCKST,CAAOK,EAAYC,EAASlB,EAAME,GAUzC,SAAe4B,EAAOT,GACrB,GAAKS,EACJ,OAAOX,EAAMW,GAEdX,EAAM,KAAME,EACZ,GACD,CACF,CE1EA,SAASgB,EAAkBpB,EAAYC,EAASpB,EAASC,EAAKoB,GAC7D,GAAKhB,UAAUC,OAAS,EACvB,OAAOP,EAASC,EAATD,CAAoBoB,EAAYC,EAASnB,GAEjDF,EAASC,EAASC,EAAlBF,CAAyBoB,EAAYC,EAASC,EAC/C,CClBAmB,EAAAC,EAAA,UAAA1C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 69bcdc8..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From c2c5b17a95f3197d7d84988f47776e3bb6c1a572 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 08:22:57 +0000 Subject: [PATCH 132/147] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 245 -- CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.factory.js | 73 - benchmark/benchmark.js | 160 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 224 - docs/types/test.ts | 166 - examples/index.js | 55 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 164 - lib/index.js | 77 - lib/limit.js | 142 - lib/main.js | 95 - lib/validate.js | 80 - package.json | 65 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 1095 ----- test/test.js | 38 - test/test.main.js | 1035 ----- test/test.validate.js | 181 - 50 files changed, 4873 insertions(+), 7211 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/limit.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 36f5de1..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-10-01T03:30:48.987Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1e08946..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 5358060..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index fa37f2d..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '37 1 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -460,7 +457,7 @@ reduceRightAsync( files, acc, read, done ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -531,11 +528,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right +[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right/tree/esm -[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce +[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index b155fd2..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var reduceRightAsync; - var arr; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - reduceRightAsync = factory( onItem ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - var acc; - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index af5c346..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var reduceRightAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=false', function benchmark( b ) { - var opts; - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'series': false - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var arr; - var len; - var acc; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'limit': 3 - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b8adcd2..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right" -%% click B href "https://github.com/stdlib-js/utils-async-reduce-right/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-reduce-right/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-reduce-right/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-reduce-right/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right -[production-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-async-reduce-right/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-async-reduce-right/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-async-reduce-right/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 47a072e..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import reduceRightAsync from '../docs/types/index'; -export = reduceRightAsync; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 530ca4d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var c=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var x=c(function(U,O){ -var R=require('@stdlib/assert-is-plain-object/dist'),h=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,k=require('@stdlib/assert-is-positive-integer/dist').isPrimitive,d=require('@stdlib/error-tools-fmtprodmsg/dist');function I(e,r){return R(r)?(h(r,"thisArg")&&(e.thisArg=r.thisArg),h(r,"series")&&(e.series=r.series,!j(e.series))?new TypeError(d('1RZ2o',"series",e.series)):h(r,"limit")&&(e.limit=r.limit,!k(e.limit))?new TypeError(d('1RZ3P',"limit",e.limit)):null):new TypeError(d('1RZ2V',r));}O.exports=I -});var P=c(function(W,E){ -var J=require("debug"),a=J("reduce-right-async:limit");function L(e,r,i,t,s){var f,m,v,n,u,g;if(n=e.length,a("Collection length: %d",n),n===0)return a("Finished processing a collection."),s(null,r);for(n0&&o();function o(){u-=1,a("Collection element %d: %s.",u,JSON.stringify(e[u])),t.length===3?t.call(i.thisArg,r,e[u],l):t.length===4?t.call(i.thisArg,r,e[u],u,l):t.call(i.thisArg,r,e[u],u,e,l);function l(w,A){if(!m){if(w)return m=!0,b(w);a("Accumulator: %s",JSON.stringify(A)),r=A,b()}}}function b(l){if(l)return a("Encountered an error: %s",l.message),s(l);if(f+=1,a("Processed %d of %d collection elements.",f,n),u>0)return o();if(f===n)return a("Finished processing a collection."),s(null,r)}}E.exports=L -});var q=c(function(X,F){ -var T=require('@stdlib/assert-is-function/dist'),S=require('@stdlib/assert-is-collection/dist'),y=require('@stdlib/error-tools-fmtprodmsg/dist'),B=require('@stdlib/constants-float64-pinf/dist'),z=x(),D=P();function G(e,r){var i,t,s;if(i={},arguments.length>1){if(t=z(i,e),t)throw t;s=r}else s=e;if(!T(s))throw new TypeError(y('1RZ3q',s));return i.series===void 0&&i.limit===void 0&&(i.series=!0),i.series?i.limit=1:i.limit||(i.limit=B),f;function f(m,v,n){if(!S(m))throw new TypeError(y('1RZAh',m));if(!T(n))throw new TypeError(y('1RZ3q',n));return D(m,v,i,s,u);function u(g,o){if(g)return n(g);n(null,o)}}}F.exports=G -});var N=c(function(Y,C){ -var p=q();function H(e,r,i,t,s){if(arguments.length<5)return p(i)(e,r,t);p(i,t)(e,r,s)}C.exports=H -});var K=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),V=N(),M=q();K(V,"factory",M);module.exports=V; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index acb9d67..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/limit.js", "../lib/factory.js", "../lib/main.js", "../lib/index.js"], - "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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\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 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 to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\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 === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, 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 ( !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, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\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* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nmodule.exports = reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' );\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, 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"], - "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,0BAA2B,EAkB/C,SAASE,EAAOC,EAAYC,EAAKC,EAAMC,EAAKC,EAAO,CAClD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMR,EAAW,OACjBF,EAAO,wBAAyBU,CAAI,EAE/BA,IAAQ,EACZ,OAAAV,EAAO,mCAAoC,EACpCM,EAAM,KAAMH,CAAI,EAYxB,IAVKO,EAAMN,EAAK,MACfK,EAAMC,EAEND,EAAML,EAAK,MAEZJ,EAAO,wBAAyBS,CAAI,EACpCT,EAAO,0BAA2BK,EAAI,MAAO,EAE7CE,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVE,EAAK,EAQP,SAASA,GAAO,CACfF,GAAO,EACPX,EAAO,6BAA8BW,EAAK,KAAK,UAAWT,EAAYS,CAAI,CAAE,CAAE,EACzEN,EAAI,SAAW,EACnBA,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGG,CAAG,EACxCT,EAAI,SAAW,EAC1BA,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGA,EAAKG,CAAG,EAExDT,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGA,EAAKT,EAAYY,CAAG,EAUrE,SAASA,EAAIC,EAAOC,EAAS,CAC5B,GAAK,CAAAR,EAIL,IAAKO,EACJ,OAAAP,EAAM,GACCS,EAAMF,CAAM,EAEpBf,EAAO,kBAAmB,KAAK,UAAWgB,CAAO,CAAE,EACnDb,EAAMa,EACNC,EAAK,EACN,CACD,CASA,SAASA,EAAMF,EAAQ,CACtB,GAAKA,EACJ,OAAAf,EAAO,2BAA4Be,EAAM,OAAQ,EAC1CT,EAAMS,CAAM,EAIpB,GAFAR,GAAS,EACTP,EAAO,0CAA2CO,EAAOG,CAAI,EACxDC,EAAM,EACV,OAAOE,EAAK,EAEb,GAAKN,IAAUG,EACd,OAAAV,EAAO,mCAAoC,EACpCM,EAAM,KAAMH,CAAI,CAEzB,CACD,CAKAL,EAAO,QAAUG,IC7IjB,IAAAiB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,gCAAiC,EACjDC,EAAW,IACXC,EAAQ,IAoEZ,SAASC,EAASC,EAASC,EAAM,CAChC,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,CAACP,EAAYW,CAAE,EACnB,MAAM,IAAI,UAAWT,EAAQ,mEAAoES,CAAE,CAAE,EAEtG,OAAKF,EAAK,SAAW,QAAUA,EAAK,QAAU,SAC7CA,EAAK,OAAS,IAEVA,EAAK,OACTA,EAAK,MAAQ,EACDA,EAAK,QACjBA,EAAK,MAAQN,GAEPS,EAaP,SAASA,EAAkBC,EAAYC,EAASC,EAAO,CACtD,GAAK,CAACd,EAAcY,CAAW,EAC9B,MAAM,IAAI,UAAWX,EAAQ,sEAAuEW,CAAW,CAAE,EAElH,GAAK,CAACb,EAAYe,CAAK,EACtB,MAAM,IAAI,UAAWb,EAAQ,mEAAoEa,CAAK,CAAE,EAEzG,OAAOV,EAAOQ,EAAYC,EAASL,EAAME,EAAGK,CAAK,EAUjD,SAASA,EAAMC,EAAOC,EAAM,CAC3B,GAAKD,EACJ,OAAOF,EAAME,CAAM,EAEpBF,EAAM,KAAMG,CAAI,CACjB,CACD,CACD,CAKAnB,EAAO,QAAUO,ICnKjB,IAAAa,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,IA8Dd,SAASC,EAAkBC,EAAYC,EAASC,EAASC,EAAKC,EAAO,CACpE,GAAK,UAAU,OAAS,EACvB,OAAON,EAASI,CAAQ,EAAGF,EAAYC,EAASE,CAAI,EAErDL,EAASI,EAASC,CAAI,EAAGH,EAAYC,EAASG,CAAK,CACpD,CAKAP,EAAO,QAAUE,IC9BjB,IAAIM,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "isPositiveInteger", "format", "validate", "opts", "options", "require_limit", "__commonJSMin", "exports", "module", "logger", "debug", "limit", "collection", "acc", "opts", "fcn", "done", "count", "flg", "lim", "len", "idx", "i", "next", "cb", "error", "result", "clbk", "require_factory", "__commonJSMin", "exports", "module", "isFunction", "isCollection", "format", "PINF", "validate", "limit", "factory", "options", "fcn", "opts", "err", "f", "reduceRightAsync", "collection", "initial", "done", "clbk", "error", "acc", "require_main", "__commonJSMin", "exports", "module", "factory", "reduceRightAsync", "collection", "initial", "options", "fcn", "done", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 078b453..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,224 +0,0 @@ - -{{alias}}( collection, initial, [options,] reducer, done ) - Applies a function against an accumulator and each element in a collection - and returns the accumulated result, iterating from right to left. - - When invoked, `reducer` is provided a maximum of five arguments: - - - accumulator: accumulated value. - - value: collection value. - - index: collection index. - - collection: the input collection. - - next: a callback to be invoked after processing a collection `value`. - - The actual number of provided arguments depends on function length. If - `reducer` accepts three arguments, `reducer` is provided: - - - accumulator - - value - - next - - If `reducer` accepts four arguments, `reducer` is provided: - - - accumulator - - value - - index - - next - - For every other `reducer` signature, `reducer` is provided all five - arguments. - - The `next` callback accepts two arguments: - - - error: error argument. - - accumulator: accumulated value. - - If a provided function calls the `next` callback with a truthy `error` - argument, the function suspends execution and immediately calls the `done` - callback for subsequent `error` handling. - - Execution is *not* guaranteed to be asynchronous. To guarantee asynchrony, - 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`). - - The function does not support dynamic collection resizing. - - If provided an empty collection, the function invokes the `done` callback - with the `initial` value as the second argument. - - The function does not skip `undefined` elements. - - When processing collection elements concurrently, *beware* of race - conditions when updating an accumulator. This is especially true when an - accumulator is a primitive (e.g., a number). In general, prefer object - accumulators. - - Parameters - ---------- - collection: Array|TypedArray|Object - Input collection over which to iterate. If provided an object, the - object must be array-like (excluding strings and functions). - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - reducer: Function - The function to invoke for each element in a collection. - - done: Function - A callback invoked either upon processing all collection elements or - upon encountering an error. - - Examples - -------- - // Basic usage: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, fcn, done ) - 3000 - 2500 - 1000 - 6500 - - // Limit number of concurrent invocations: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'limit': 2 }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 2500 - 3000 - 1000 - 6500 - - // Process concurrently: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'series': false }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 1000 - 2500 - 3000 - 6500 - - -{{alias}}.factory( [options,] fcn ) - Returns a function which applies a function against an accumulator and each - element in a collection and returns the accumulated result, iterating from - right to left. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - fcn: Function - The function to invoke for each element in a collection. - - Returns - ------- - out: Function - A function which invokes a function for each element in a collection. - - Examples - -------- - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > var opts = { 'series': false }; - > var f = {{alias}}.factory( opts, fcn ); - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > f( arr, acc, done ) - 1000 - 2500 - 3000 - 6500 - > acc = { 'sum': 0 }; - > arr = [ 1000, 1500, 2000 ]; - > f( arr, acc, done ) - 1000 - 1500 - 2000 - 4500 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0455864..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,166 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unsafe-assignment */ - -import reduceRightAsync = require( './index' ); - -const reducer = ( acc: any, value: number, index: number, next: Function ) => { - acc.sum += value; - if ( index === void 0 ) { - throw new Error( '`index` is missing.' ); - } - next( null, acc ); -}; - -const done = ( error: Error | null, acc: any ) => { - if ( error ) { - throw error; - } - if ( acc === void 0 ) { - throw new Error( '`acc` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( 2, acc, reducer, done ); // $ExpectError - reduceRightAsync( false, acc, reducer, done ); // $ExpectError - reduceRightAsync( true, acc, reducer, done ); // $ExpectError - reduceRightAsync( {}, acc, reducer, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a predicate argument which is not a predicate function... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 2, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, false, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, true, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 'abc', done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, [], done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a done callback argument which is not a function having a supported signature... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 2 ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, false ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, true ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 'abc' ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, {} ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, [] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const acc = { 'sum': 0 }; - reduceRightAsync(); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, reducer, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - reduceRightAsync.factory( reducer ); // $ExpectType FactoryFunction - reduceRightAsync.factory( { 'series': true }, reducer ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - reduceRightAsync.factory( [], reducer ); // $ExpectError - reduceRightAsync.factory( 123, reducer ); // $ExpectError - reduceRightAsync.factory( 'abc', reducer ); // $ExpectError - reduceRightAsync.factory( false, reducer ); // $ExpectError - reduceRightAsync.factory( true, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not a predicate function... -{ - reduceRightAsync.factory( {} ); // $ExpectError - reduceRightAsync.factory( true ); // $ExpectError - reduceRightAsync.factory( false ); // $ExpectError - reduceRightAsync.factory( {}, 123 ); // $ExpectError - reduceRightAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1( 12, acc, done ); // $ExpectError - fcn1( true, acc, done ); // $ExpectError - fcn1( false, acc, done ); // $ExpectError - fcn1( {}, acc, done ); // $ExpectError - - fcn1( [ 3000, 2500, 1000 ], acc, 12 ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, true ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, false ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, '5' ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, {} ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, [] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1(); // $ExpectError - fcn1( [ 3000, 2500, 1000 ] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - reduceRightAsync.factory( { 'limit': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': true }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': false }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - reduceRightAsync.factory( { 'series': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': 12 }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - reduceRightAsync.factory(); // $ExpectError - reduceRightAsync.factory( {}, reducer, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index dd64345..0000000 --- a/examples/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var resolve = require( 'path' ).resolve; -var readFile = require( '@stdlib/fs-read-file' ); -var reduceRightAsync = require( './../lib' ); - -var files = [ - resolve( __dirname, '..', 'package.json' ), - resolve( __dirname, '..', 'README.md' ) -]; - -function done( error, acc ) { - if ( error ) { - throw error; - } - console.log( acc.count ); -} - -function read( acc, file, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( file, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( null, acc ); - } - acc.count += 1; - next( null, acc ); - } -} - -var acc = { - 'count': 0 -}; -reduceRightAsync( files, acc, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 28e0a36..f6cba5d 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..234a485 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as c}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";function m(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var d=m(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function f(e,m){var f,u,p;if(f={},arguments.length>1){if(u=function(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("1RZ2o","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!c(e.limit))?new TypeError(r("1RZ3P","limit",e.limit)):null):new TypeError(r("1RZ2V",t))}(f,e),u)throw u;p=m}else p=e;if(!t(p))throw new TypeError(r("1RZ3q",p));return void 0===f.series&&void 0===f.limit&&(f.series=!0),f.series?f.limit=1:f.limit||(f.limit=s),function(e,s,n){if(!i(e))throw new TypeError(r("1RZAh",e));if(!t(n))throw new TypeError(r("1RZ3q",n));return function(e,t,i,r,s){var n,o,l,c,m,f;if(c=e.length,d("Collection length: %d",c),0===c)return d("Finished processing a collection."),s(null,t);for(l=c0&&u();function u(){function s(e,i){if(!o){if(e)return o=!0,p(e);d("Accumulator: %s",JSON.stringify(i)),t=i,p()}}d("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function p(e){return e?(d("Encountered an error: %s",e.message),s(e)):(d("Processed %d of %d collection elements.",n+=1,c),m>0?u():n===c?(d("Finished processing a collection."),s(null,t)):void 0)}}(e,s,f,p,(function(e,t){if(e)return n(e);n(null,t)}))}}function u(e,t,i,r,s){if(arguments.length<5)return f(i)(e,t,r);f(i,r)(e,t,s)}e(u,"factory",f);export{u as default,f as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..e11f2cb --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/limit.js","../lib/factory.js","../lib/validate.js","../lib/main.js","../lib/index.js"],"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 logger = require( 'debug' );\n\n\n// VARIABLES //\n\nvar debug = logger( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RZ3q', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '1RZAh', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RZ3q', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '1RZ2V', 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( '1RZ2o', '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( '1RZ3P', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["debug","logger","factory","options","fcn","opts","err","f","arguments","length","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","validate","isFunction","PINF","collection","initial","done","isCollection","acc","count","flg","lim","len","idx","i","next","cb","error","result","clbk","JSON","stringify","call","message","reduceRightAsync","setReadOnly","main"],"mappings":";;81CA2BIA,uDAAQC,CAAQ,4BCoEpB,SAASC,EAASC,EAASC,GAC1B,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAA,EACFG,UAAUC,OAAS,EAAI,CAE3B,GADAH,EChDF,SAAmBD,EAAMF,GACxB,OAAMO,EAAUP,IAGXQ,EAAYR,EAAS,aACzBE,EAAKO,QAAUT,EAAQS,SAEnBD,EAAYR,EAAS,YACzBE,EAAKQ,OAASV,EAAQU,QAChBC,EAAWT,EAAKQ,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUX,EAAKQ,SAGnDF,EAAYR,EAAS,WACzBE,EAAKY,MAAQd,EAAQc,OACfC,EAAmBb,EAAKY,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASX,EAAKY,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASb,GAkBzC,CD4BQgB,CAAUd,EAAMF,GACjBG,EACJ,MAAMA,EAEPC,EAAIH,CACN,MACEG,EAAIJ,EAEL,IAAMiB,EAAYb,GACjB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAUvC,YARqB,IAAhBF,EAAKQ,aAAoC,IAAfR,EAAKY,QACnCZ,EAAKQ,QAAS,GAEVR,EAAKQ,OACTR,EAAKY,MAAQ,EACDZ,EAAKY,QACjBZ,EAAKY,MAAQI,GAed,SAA2BC,EAAYC,EAASC,GAC/C,IAAMC,EAAcH,GACnB,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,IAAMF,EAAYI,GACjB,MAAM,IAAIT,UAAWC,EAAQ,QAASQ,IAEvC,ODhGF,SAAgBF,EAAYI,EAAKrB,EAAMD,EAAKoB,GAC3C,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMR,EAAWb,OACjBT,EAAO,wBAAyB8B,GAEnB,IAARA,EAEJ,OADA9B,EAAO,qCACAwB,EAAM,KAAME,GAYpB,IATCG,EADIC,EAAMzB,EAAKY,MACTa,EAEAzB,EAAKY,MAEZjB,EAAO,wBAAyB6B,GAChC7B,EAAO,0BAA2BI,EAAIK,QAEtCkB,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVE,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKR,EAAL,CAIA,GAAKO,EAEJ,OADAP,GAAM,EACCS,EAAMF,GAEdnC,EAAO,kBAAmBsC,KAAKC,UAAWH,IAC1CV,EAAMU,EACNC,GAPC,CAQD,CA5BDrC,EAAO,6BADP+B,GAAO,EACmCO,KAAKC,UAAWjB,EAAYS,KAClD,IAAf3B,EAAIK,OACRL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOG,GACtB,IAAf9B,EAAIK,OACfL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKG,GAErD9B,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKT,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJnC,EAAO,2BAA4BmC,EAAMM,SAClCjB,EAAMW,KAGdnC,EAAO,0CADP2B,GAAS,EACgDG,GACpDC,EAAM,EACHE,IAEHN,IAAUG,GACd9B,EAAO,qCACAwB,EAAM,KAAME,SAFpB,EAIA,CACF,CCKST,CAAOK,EAAYC,EAASlB,EAAME,GAUzC,SAAe4B,EAAOT,GACrB,GAAKS,EACJ,OAAOX,EAAMW,GAEdX,EAAM,KAAME,EACZ,GACD,CACF,CE1EA,SAASgB,EAAkBpB,EAAYC,EAASpB,EAASC,EAAKoB,GAC7D,GAAKhB,UAAUC,OAAS,EACvB,OAAOP,EAASC,EAATD,CAAoBoB,EAAYC,EAASnB,GAEjDF,EAASC,EAASC,EAAlBF,CAAyBoB,EAAYC,EAASC,EAC/C,CClBAmB,EAAAC,EAAA,UAAA1C"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index e107128..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,164 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var validate = require( './validate.js' ); -var limit = require( './limit.js' ); - - -// MAIN // - -/** -* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} last argument must be a function -* @returns {Function} function which invokes the provided function once for each element in a collection -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error, data ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var opts = { -* 'series': false -* }; -* -* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: -* var reduceRightAsync = factory( opts, read ); -* -* // Create a collection over which to iterate: -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* // Define a callback which handles errors: -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* // Run `read` for each element in `files`: -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, done ); -*/ -function factory( options, fcn ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = fcn; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '1RZ3q', f ) ); - } - if ( opts.series === void 0 && opts.limit === void 0 ) { - opts.series = true; - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return reduceRightAsync; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * @private - * @param {Collection} collection - input collection - * @param {*} initial - initial value - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be a collection - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function reduceRightAsync( collection, initial, done ) { - if ( !isCollection( collection ) ) { - throw new TypeError( format( '1RZAh', collection ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '1RZ3q', done ) ); - } - return limit( collection, initial, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {*} [acc] - accumulated value - * @returns {void} - */ - function clbk( error, acc ) { - if ( error ) { - return done( error ); - } - done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ae657ff..0000000 --- a/lib/index.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* @module @stdlib/utils-async-reduce-right -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' ); -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/limit.js b/lib/limit.js deleted file mode 100644 index cdb60af..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); - - -// VARIABLES // - -var debug = logger( 'reduce-right-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each element in a collection, limiting the number of concurrently pending functions and iterating from right to left. -* -* @private -* @param {Collection} collection - input collection -* @param {*} acc - initial value -* @param {Options} opts - function options -* @param {*} [opts.thisArg] - execution context -* @param {PositiveInteger} [opts.limit] - maximum number of pending function invocations -* @param {Function} fcn - function to invoke -* @param {Callback} done - function to invoke upon completion or upon encountering an error -* @returns {void} -*/ -function limit( collection, acc, opts, fcn, done ) { - var count; - var flg; - var lim; - var len; - var idx; - var i; - - len = collection.length; - debug( 'Collection length: %d', len ); - - if ( len === 0 ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - count = 0; - idx = len; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all collection elements... - if ( idx > 0 ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next element in a collection. - * - * @private - */ - function next() { - idx -= 1; - debug( 'Collection element %d: %s.', idx, JSON.stringify( collection[ idx ] ) ); - if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], cb ); - } else if ( fcn.length === 4 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, cb ); - } else { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len - } - /** - * Callback invoked once a provided function finishes processing a collection element. - * - * @private - * @param {*} [error] - error - * @param {*} [result] - accumulation result - * @returns {void} - */ - function cb( error, result ) { - if ( flg ) { - // Prevent further processing of collection elements: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Accumulator: %s', JSON.stringify( result ) ); - acc = result; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next collection element. - * - * @private - * @param {*} [error] - error - * @returns {void} - */ - function clbk( error ) { - if ( error ) { - debug( 'Encountered an error: %s', error.message ); - return done( error ); - } - count += 1; - debug( 'Processed %d of %d collection elements.', count, len ); - if ( idx > 0 ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index c8b0d0f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param {Collection} collection - input collection -* @param {*} initial - initial value -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} second-to-last argument must be a function -* @throws {TypeError} last argument must be a function -* @returns {void} -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -function reduceRightAsync( collection, initial, options, fcn, done ) { - if ( arguments.length < 5 ) { - return factory( options )( collection, initial, fcn ); - } - factory( options, fcn )( collection, initial, done ); -} - - -// EXPORTS // - -module.exports = reduceRightAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 0c666fe..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @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 -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'thisArg': {}, -* 'series': false, -* 'limit': 10 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '1RZ2V', options ) ); - } - if ( hasOwnProp( options, 'thisArg' ) ) { - opts.thisArg = options.thisArg; - } - if ( hasOwnProp( options, 'series' ) ) { - opts.series = options.series; - if ( !isBoolean( opts.series ) ) { - return new TypeError( format( '1RZ2o', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '1RZ3P', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 0c316c5..563c57c 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,44 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-collection": "^0.2.2", - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/assert-is-positive-integer": "^0.2.2", - "@stdlib/constants-float64-pinf": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "debug": "^2.6.9", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/constants-float64-eps": "^0.2.2", - "@stdlib/fs-read-file": "^0.2.2", - "@stdlib/utils-noop": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..69bcdc8 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 8244931..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1095 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( {}, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, next ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - factory( opts, next ); - }; - } -}); - -tape( 'the function returns a function (no options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided a collection (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a collection (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (1 argument)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (2 arguments)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with five arguments', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn() { - var value; - var next; - var acc; - var k; - - acc = arguments[ 0 ]; - value = arguments[ 1 ]; - k = arguments[ 2 ]; - next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( k, i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the returned function supports processing collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements concurrently', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 100, 250, 300 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements sequentially (limit = 1)', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of collection elements which are processed at any one time', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 250, 300, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 250, 100, 300 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var reduceRightAsync; - var arr; - - reduceRightAsync = factory( fcn ); - arr = []; - - reduceRightAsync( arr, 0, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var reduceRightAsync; - var obj; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = []; - obj = {}; - reduceRightAsync( arr, obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - i = 0; - - reduceRightAsync( arr, {}, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, acc ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the returned function does not skip empty elements', function test( t ) { - var reduceRightAsync; - var expected; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index f273a40..0000000 --- a/test/test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof reduceRightAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 1893240..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1035 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a collection', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (no options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, next, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, 0 ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - reduceRightAsync( [ 1, 2, 3 ], 0, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (1 argument)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (2 arguments)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with five arguments', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn() { - var next; - var acc; - var v; - - next = arguments[ 4 ]; - acc = arguments[ 0 ]; - v = arguments[ 1 ]; - - i -= 1; - j += 1; - - t.strictEqual( v, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, v ); - - function onTimeout() { - acc.sum += v; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'by default, the function processes collection elements sequentially', function test( t ) { - var values; - var count; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements concurrently', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 100, 250, 300 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': true - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially (limit = 1)', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var arr; - var ctx; - - arr = [ 3, 2, 1 ]; - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 3, 2, 1 ]; - opts = { - 'series': true - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 250, 100, 300 ]; - opts = { - 'limit': 2 - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var arr = []; - reduceRightAsync( arr, 0, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var arr = []; - var obj = {}; - - reduceRightAsync( arr, obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - arr = [ 3, 2, 1 ]; - i = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, value ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the function does not skip empty elements', function test( t ) { - var expected; - var arr; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, fcn, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 7660838..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,181 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `limit` option which is not a positive integer', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - -5, - 0, - 3.14, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'limit': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `series` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'series': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function accepts any value for the `thisArg` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'thisArg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err, null, 'returns null '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'thisArg': {}, - 'series': false, - 'limit': 10 - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From b6c4916f9937bddf86d189f2686b9f9baaef275b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 04:37:48 +0000 Subject: [PATCH 133/147] Transform error messages --- lib/factory.js | 8 ++++---- lib/validate.js | 8 ++++---- package.json | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 1125052..e107128 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -22,7 +22,7 @@ var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var PINF = require( '@stdlib/constants-float64-pinf' ); var validate = require( './validate.js' ); var limit = require( './limit.js' ); @@ -109,7 +109,7 @@ function factory( options, fcn ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '1RZ3q', f ) ); } if ( opts.series === void 0 && opts.limit === void 0 ) { opts.series = true; @@ -134,10 +134,10 @@ function factory( options, fcn ) { */ function reduceRightAsync( collection, initial, done ) { if ( !isCollection( collection ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a collection. Value: `%s`.', collection ) ); + throw new TypeError( format( '1RZAh', collection ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '1RZ3q', done ) ); } return limit( collection, initial, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index 9ba927e..0c666fe 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,7 +54,7 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '1RZ2V', options ) ); } if ( hasOwnProp( options, 'thisArg' ) ) { opts.thisArg = options.thisArg; @@ -62,13 +62,13 @@ function validate( opts, options ) { if ( hasOwnProp( options, 'series' ) ) { opts.series = options.series; if ( !isBoolean( opts.series ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'series', opts.series ) ); + return new TypeError( format( '1RZ2o', 'series', opts.series ) ); } } if ( hasOwnProp( options, 'limit' ) ) { opts.limit = options.limit; if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'limit', opts.limit ) ); + return new TypeError( format( '1RZ3P', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index 739500e..0c316c5 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-plain-object": "^0.2.2", "@stdlib/assert-is-positive-integer": "^0.2.2", "@stdlib/constants-float64-pinf": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.1", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", "debug": "^2.6.9", From 611e51a6e41d28340852e29cc98609a9f627eae0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 07:55:53 +0000 Subject: [PATCH 134/147] Remove files --- index.d.ts | 410 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5257 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index f6cba5d..0000000 --- a/index.d.ts +++ /dev/null @@ -1,410 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Execution context. - */ - thisArg?: ThisParameterType>; - - /** - * The maximum number of pending invocations at any one time. - */ - limit?: number; - - /** - * Boolean indicating whether to sequentially invoke the reducer function for each `collection` element. If `true`, the function sets `options.limit=1`. Default: true. - */ - series?: boolean; -} - -/** -* Callback function. -*/ -type Nullary = () => void; - -/** -* Callback function. -* -* @param error - encountered error or null -*/ -type Unary = ( error: Error | null ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Binary = ( error: Error | null, accumulator: U ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param next - a callback to be invoked after processing a collection `value` -*/ -type TernaryReducer = ( this: V, accumulator: U, value: T, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuaternaryReducer = ( this: V, accumulator: U, value: T, index: number, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuinaryReducer = ( this: V, accumulator: U, value: T, index: number, collection: Collection, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type Reducer = TernaryReducer | QuaternaryReducer | QuinaryReducer; - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result. -* -* @param collection - input collection -* @param initial - initial value -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( collection: Collection, initial: U, done: Callback ) => void; - -/** -* Interface for `reduceRightAsync`. -*/ -interface ReduceRightAsync { - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, {}, read, done ); - */ - ( collection: Collection, initial: U, options: Options, reducer: Reducer, done: Callback ): void; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, read, done ); - */ - ( collection: Collection, initial: U, reducer: Reducer, done: Callback ): void; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @throws must provide valid options - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var opts = { - * 'series': false - * }; - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( opts, read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( options: Options, reducer: Reducer ): FactoryFunction; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param reducer - function to invoke for each element in a collection - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( reducer: Reducer ): FactoryFunction; -} - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param collection - input collection -* @param initial - initial value -* @param options - function options -* @param options.thisArg - execution context -* @param options.limit - maximum number of pending invocations at any one time -* @param 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 (default: true) -* @param reducer - function to invoke for each element in a collection -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -declare var reduceRightAsync: ReduceRightAsync; - - -// EXPORTS // - -export = reduceRightAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 234a485..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as c}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";function m(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var d=m(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function f(e,m){var f,u,p;if(f={},arguments.length>1){if(u=function(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("1RZ2o","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!c(e.limit))?new TypeError(r("1RZ3P","limit",e.limit)):null):new TypeError(r("1RZ2V",t))}(f,e),u)throw u;p=m}else p=e;if(!t(p))throw new TypeError(r("1RZ3q",p));return void 0===f.series&&void 0===f.limit&&(f.series=!0),f.series?f.limit=1:f.limit||(f.limit=s),function(e,s,n){if(!i(e))throw new TypeError(r("1RZAh",e));if(!t(n))throw new TypeError(r("1RZ3q",n));return function(e,t,i,r,s){var n,o,l,c,m,f;if(c=e.length,d("Collection length: %d",c),0===c)return d("Finished processing a collection."),s(null,t);for(l=c0&&u();function u(){function s(e,i){if(!o){if(e)return o=!0,p(e);d("Accumulator: %s",JSON.stringify(i)),t=i,p()}}d("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function p(e){return e?(d("Encountered an error: %s",e.message),s(e)):(d("Processed %d of %d collection elements.",n+=1,c),m>0?u():n===c?(d("Finished processing a collection."),s(null,t)):void 0)}}(e,s,f,p,(function(e,t){if(e)return n(e);n(null,t)}))}}function u(e,t,i,r,s){if(arguments.length<5)return f(i)(e,t,r);f(i,r)(e,t,s)}e(u,"factory",f);export{u as default,f as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index e11f2cb..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/limit.js","../lib/factory.js","../lib/validate.js","../lib/main.js","../lib/index.js"],"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 logger = require( 'debug' );\n\n\n// VARIABLES //\n\nvar debug = logger( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RZ3q', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '1RZAh', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RZ3q', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '1RZ2V', 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( '1RZ2o', '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( '1RZ3P', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["debug","logger","factory","options","fcn","opts","err","f","arguments","length","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","validate","isFunction","PINF","collection","initial","done","isCollection","acc","count","flg","lim","len","idx","i","next","cb","error","result","clbk","JSON","stringify","call","message","reduceRightAsync","setReadOnly","main"],"mappings":";;81CA2BIA,uDAAQC,CAAQ,4BCoEpB,SAASC,EAASC,EAASC,GAC1B,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAA,EACFG,UAAUC,OAAS,EAAI,CAE3B,GADAH,EChDF,SAAmBD,EAAMF,GACxB,OAAMO,EAAUP,IAGXQ,EAAYR,EAAS,aACzBE,EAAKO,QAAUT,EAAQS,SAEnBD,EAAYR,EAAS,YACzBE,EAAKQ,OAASV,EAAQU,QAChBC,EAAWT,EAAKQ,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUX,EAAKQ,SAGnDF,EAAYR,EAAS,WACzBE,EAAKY,MAAQd,EAAQc,OACfC,EAAmBb,EAAKY,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASX,EAAKY,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASb,GAkBzC,CD4BQgB,CAAUd,EAAMF,GACjBG,EACJ,MAAMA,EAEPC,EAAIH,CACN,MACEG,EAAIJ,EAEL,IAAMiB,EAAYb,GACjB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAUvC,YARqB,IAAhBF,EAAKQ,aAAoC,IAAfR,EAAKY,QACnCZ,EAAKQ,QAAS,GAEVR,EAAKQ,OACTR,EAAKY,MAAQ,EACDZ,EAAKY,QACjBZ,EAAKY,MAAQI,GAed,SAA2BC,EAAYC,EAASC,GAC/C,IAAMC,EAAcH,GACnB,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,IAAMF,EAAYI,GACjB,MAAM,IAAIT,UAAWC,EAAQ,QAASQ,IAEvC,ODhGF,SAAgBF,EAAYI,EAAKrB,EAAMD,EAAKoB,GAC3C,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMR,EAAWb,OACjBT,EAAO,wBAAyB8B,GAEnB,IAARA,EAEJ,OADA9B,EAAO,qCACAwB,EAAM,KAAME,GAYpB,IATCG,EADIC,EAAMzB,EAAKY,MACTa,EAEAzB,EAAKY,MAEZjB,EAAO,wBAAyB6B,GAChC7B,EAAO,0BAA2BI,EAAIK,QAEtCkB,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVE,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKR,EAAL,CAIA,GAAKO,EAEJ,OADAP,GAAM,EACCS,EAAMF,GAEdnC,EAAO,kBAAmBsC,KAAKC,UAAWH,IAC1CV,EAAMU,EACNC,GAPC,CAQD,CA5BDrC,EAAO,6BADP+B,GAAO,EACmCO,KAAKC,UAAWjB,EAAYS,KAClD,IAAf3B,EAAIK,OACRL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOG,GACtB,IAAf9B,EAAIK,OACfL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKG,GAErD9B,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKT,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJnC,EAAO,2BAA4BmC,EAAMM,SAClCjB,EAAMW,KAGdnC,EAAO,0CADP2B,GAAS,EACgDG,GACpDC,EAAM,EACHE,IAEHN,IAAUG,GACd9B,EAAO,qCACAwB,EAAM,KAAME,SAFpB,EAIA,CACF,CCKST,CAAOK,EAAYC,EAASlB,EAAME,GAUzC,SAAe4B,EAAOT,GACrB,GAAKS,EACJ,OAAOX,EAAMW,GAEdX,EAAM,KAAME,EACZ,GACD,CACF,CE1EA,SAASgB,EAAkBpB,EAAYC,EAASpB,EAASC,EAAKoB,GAC7D,GAAKhB,UAAUC,OAAS,EACvB,OAAOP,EAASC,EAATD,CAAoBoB,EAAYC,EAASnB,GAEjDF,EAASC,EAASC,EAAlBF,CAAyBoB,EAAYC,EAASC,EAC/C,CClBAmB,EAAAC,EAAA,UAAA1C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 69bcdc8..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 91b6cc28044a4e35cae7792b39159da657d1540e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 07:56:05 +0000 Subject: [PATCH 135/147] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 245 -- CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.factory.js | 73 - benchmark/benchmark.js | 160 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 224 - docs/types/test.ts | 166 - examples/index.js | 55 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 164 - lib/index.js | 77 - lib/limit.js | 142 - lib/main.js | 95 - lib/validate.js | 80 - package.json | 65 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 1095 ----- test/test.js | 38 - test/test.main.js | 1035 ----- test/test.validate.js | 181 - 50 files changed, 4873 insertions(+), 7211 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/limit.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 44bbf99..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-11-01T03:33:29.431Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1e08946..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 5358060..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index fa37f2d..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '37 1 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -460,7 +457,7 @@ reduceRightAsync( files, acc, read, done ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -531,11 +528,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right +[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right/tree/esm -[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce +[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index b155fd2..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var reduceRightAsync; - var arr; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - reduceRightAsync = factory( onItem ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - var acc; - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index af5c346..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var reduceRightAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=false', function benchmark( b ) { - var opts; - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'series': false - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var arr; - var len; - var acc; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'limit': 3 - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b8adcd2..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right" -%% click B href "https://github.com/stdlib-js/utils-async-reduce-right/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-reduce-right/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-reduce-right/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-reduce-right/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right -[production-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-async-reduce-right/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-async-reduce-right/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-async-reduce-right/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 47a072e..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import reduceRightAsync from '../docs/types/index'; -export = reduceRightAsync; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 530ca4d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var c=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var x=c(function(U,O){ -var R=require('@stdlib/assert-is-plain-object/dist'),h=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,k=require('@stdlib/assert-is-positive-integer/dist').isPrimitive,d=require('@stdlib/error-tools-fmtprodmsg/dist');function I(e,r){return R(r)?(h(r,"thisArg")&&(e.thisArg=r.thisArg),h(r,"series")&&(e.series=r.series,!j(e.series))?new TypeError(d('1RZ2o',"series",e.series)):h(r,"limit")&&(e.limit=r.limit,!k(e.limit))?new TypeError(d('1RZ3P',"limit",e.limit)):null):new TypeError(d('1RZ2V',r));}O.exports=I -});var P=c(function(W,E){ -var J=require("debug"),a=J("reduce-right-async:limit");function L(e,r,i,t,s){var f,m,v,n,u,g;if(n=e.length,a("Collection length: %d",n),n===0)return a("Finished processing a collection."),s(null,r);for(n0&&o();function o(){u-=1,a("Collection element %d: %s.",u,JSON.stringify(e[u])),t.length===3?t.call(i.thisArg,r,e[u],l):t.length===4?t.call(i.thisArg,r,e[u],u,l):t.call(i.thisArg,r,e[u],u,e,l);function l(w,A){if(!m){if(w)return m=!0,b(w);a("Accumulator: %s",JSON.stringify(A)),r=A,b()}}}function b(l){if(l)return a("Encountered an error: %s",l.message),s(l);if(f+=1,a("Processed %d of %d collection elements.",f,n),u>0)return o();if(f===n)return a("Finished processing a collection."),s(null,r)}}E.exports=L -});var q=c(function(X,F){ -var T=require('@stdlib/assert-is-function/dist'),S=require('@stdlib/assert-is-collection/dist'),y=require('@stdlib/error-tools-fmtprodmsg/dist'),B=require('@stdlib/constants-float64-pinf/dist'),z=x(),D=P();function G(e,r){var i,t,s;if(i={},arguments.length>1){if(t=z(i,e),t)throw t;s=r}else s=e;if(!T(s))throw new TypeError(y('1RZ3q',s));return i.series===void 0&&i.limit===void 0&&(i.series=!0),i.series?i.limit=1:i.limit||(i.limit=B),f;function f(m,v,n){if(!S(m))throw new TypeError(y('1RZAh',m));if(!T(n))throw new TypeError(y('1RZ3q',n));return D(m,v,i,s,u);function u(g,o){if(g)return n(g);n(null,o)}}}F.exports=G -});var N=c(function(Y,C){ -var p=q();function H(e,r,i,t,s){if(arguments.length<5)return p(i)(e,r,t);p(i,t)(e,r,s)}C.exports=H -});var K=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),V=N(),M=q();K(V,"factory",M);module.exports=V; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index acb9d67..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/limit.js", "../lib/factory.js", "../lib/main.js", "../lib/index.js"], - "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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\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 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 to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\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 === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, 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 ( !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, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\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* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nmodule.exports = reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' );\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, 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"], - "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,0BAA2B,EAkB/C,SAASE,EAAOC,EAAYC,EAAKC,EAAMC,EAAKC,EAAO,CAClD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMR,EAAW,OACjBF,EAAO,wBAAyBU,CAAI,EAE/BA,IAAQ,EACZ,OAAAV,EAAO,mCAAoC,EACpCM,EAAM,KAAMH,CAAI,EAYxB,IAVKO,EAAMN,EAAK,MACfK,EAAMC,EAEND,EAAML,EAAK,MAEZJ,EAAO,wBAAyBS,CAAI,EACpCT,EAAO,0BAA2BK,EAAI,MAAO,EAE7CE,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVE,EAAK,EAQP,SAASA,GAAO,CACfF,GAAO,EACPX,EAAO,6BAA8BW,EAAK,KAAK,UAAWT,EAAYS,CAAI,CAAE,CAAE,EACzEN,EAAI,SAAW,EACnBA,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGG,CAAG,EACxCT,EAAI,SAAW,EAC1BA,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGA,EAAKG,CAAG,EAExDT,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGA,EAAKT,EAAYY,CAAG,EAUrE,SAASA,EAAIC,EAAOC,EAAS,CAC5B,GAAK,CAAAR,EAIL,IAAKO,EACJ,OAAAP,EAAM,GACCS,EAAMF,CAAM,EAEpBf,EAAO,kBAAmB,KAAK,UAAWgB,CAAO,CAAE,EACnDb,EAAMa,EACNC,EAAK,EACN,CACD,CASA,SAASA,EAAMF,EAAQ,CACtB,GAAKA,EACJ,OAAAf,EAAO,2BAA4Be,EAAM,OAAQ,EAC1CT,EAAMS,CAAM,EAIpB,GAFAR,GAAS,EACTP,EAAO,0CAA2CO,EAAOG,CAAI,EACxDC,EAAM,EACV,OAAOE,EAAK,EAEb,GAAKN,IAAUG,EACd,OAAAV,EAAO,mCAAoC,EACpCM,EAAM,KAAMH,CAAI,CAEzB,CACD,CAKAL,EAAO,QAAUG,IC7IjB,IAAAiB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,gCAAiC,EACjDC,EAAW,IACXC,EAAQ,IAoEZ,SAASC,EAASC,EAASC,EAAM,CAChC,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,CAACP,EAAYW,CAAE,EACnB,MAAM,IAAI,UAAWT,EAAQ,mEAAoES,CAAE,CAAE,EAEtG,OAAKF,EAAK,SAAW,QAAUA,EAAK,QAAU,SAC7CA,EAAK,OAAS,IAEVA,EAAK,OACTA,EAAK,MAAQ,EACDA,EAAK,QACjBA,EAAK,MAAQN,GAEPS,EAaP,SAASA,EAAkBC,EAAYC,EAASC,EAAO,CACtD,GAAK,CAACd,EAAcY,CAAW,EAC9B,MAAM,IAAI,UAAWX,EAAQ,sEAAuEW,CAAW,CAAE,EAElH,GAAK,CAACb,EAAYe,CAAK,EACtB,MAAM,IAAI,UAAWb,EAAQ,mEAAoEa,CAAK,CAAE,EAEzG,OAAOV,EAAOQ,EAAYC,EAASL,EAAME,EAAGK,CAAK,EAUjD,SAASA,EAAMC,EAAOC,EAAM,CAC3B,GAAKD,EACJ,OAAOF,EAAME,CAAM,EAEpBF,EAAM,KAAMG,CAAI,CACjB,CACD,CACD,CAKAnB,EAAO,QAAUO,ICnKjB,IAAAa,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,IA8Dd,SAASC,EAAkBC,EAAYC,EAASC,EAASC,EAAKC,EAAO,CACpE,GAAK,UAAU,OAAS,EACvB,OAAON,EAASI,CAAQ,EAAGF,EAAYC,EAASE,CAAI,EAErDL,EAASI,EAASC,CAAI,EAAGH,EAAYC,EAASG,CAAK,CACpD,CAKAP,EAAO,QAAUE,IC9BjB,IAAIM,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "isPositiveInteger", "format", "validate", "opts", "options", "require_limit", "__commonJSMin", "exports", "module", "logger", "debug", "limit", "collection", "acc", "opts", "fcn", "done", "count", "flg", "lim", "len", "idx", "i", "next", "cb", "error", "result", "clbk", "require_factory", "__commonJSMin", "exports", "module", "isFunction", "isCollection", "format", "PINF", "validate", "limit", "factory", "options", "fcn", "opts", "err", "f", "reduceRightAsync", "collection", "initial", "done", "clbk", "error", "acc", "require_main", "__commonJSMin", "exports", "module", "factory", "reduceRightAsync", "collection", "initial", "options", "fcn", "done", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 078b453..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,224 +0,0 @@ - -{{alias}}( collection, initial, [options,] reducer, done ) - Applies a function against an accumulator and each element in a collection - and returns the accumulated result, iterating from right to left. - - When invoked, `reducer` is provided a maximum of five arguments: - - - accumulator: accumulated value. - - value: collection value. - - index: collection index. - - collection: the input collection. - - next: a callback to be invoked after processing a collection `value`. - - The actual number of provided arguments depends on function length. If - `reducer` accepts three arguments, `reducer` is provided: - - - accumulator - - value - - next - - If `reducer` accepts four arguments, `reducer` is provided: - - - accumulator - - value - - index - - next - - For every other `reducer` signature, `reducer` is provided all five - arguments. - - The `next` callback accepts two arguments: - - - error: error argument. - - accumulator: accumulated value. - - If a provided function calls the `next` callback with a truthy `error` - argument, the function suspends execution and immediately calls the `done` - callback for subsequent `error` handling. - - Execution is *not* guaranteed to be asynchronous. To guarantee asynchrony, - 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`). - - The function does not support dynamic collection resizing. - - If provided an empty collection, the function invokes the `done` callback - with the `initial` value as the second argument. - - The function does not skip `undefined` elements. - - When processing collection elements concurrently, *beware* of race - conditions when updating an accumulator. This is especially true when an - accumulator is a primitive (e.g., a number). In general, prefer object - accumulators. - - Parameters - ---------- - collection: Array|TypedArray|Object - Input collection over which to iterate. If provided an object, the - object must be array-like (excluding strings and functions). - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - reducer: Function - The function to invoke for each element in a collection. - - done: Function - A callback invoked either upon processing all collection elements or - upon encountering an error. - - Examples - -------- - // Basic usage: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, fcn, done ) - 3000 - 2500 - 1000 - 6500 - - // Limit number of concurrent invocations: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'limit': 2 }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 2500 - 3000 - 1000 - 6500 - - // Process concurrently: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'series': false }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 1000 - 2500 - 3000 - 6500 - - -{{alias}}.factory( [options,] fcn ) - Returns a function which applies a function against an accumulator and each - element in a collection and returns the accumulated result, iterating from - right to left. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - fcn: Function - The function to invoke for each element in a collection. - - Returns - ------- - out: Function - A function which invokes a function for each element in a collection. - - Examples - -------- - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > var opts = { 'series': false }; - > var f = {{alias}}.factory( opts, fcn ); - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > f( arr, acc, done ) - 1000 - 2500 - 3000 - 6500 - > acc = { 'sum': 0 }; - > arr = [ 1000, 1500, 2000 ]; - > f( arr, acc, done ) - 1000 - 1500 - 2000 - 4500 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0455864..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,166 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unsafe-assignment */ - -import reduceRightAsync = require( './index' ); - -const reducer = ( acc: any, value: number, index: number, next: Function ) => { - acc.sum += value; - if ( index === void 0 ) { - throw new Error( '`index` is missing.' ); - } - next( null, acc ); -}; - -const done = ( error: Error | null, acc: any ) => { - if ( error ) { - throw error; - } - if ( acc === void 0 ) { - throw new Error( '`acc` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( 2, acc, reducer, done ); // $ExpectError - reduceRightAsync( false, acc, reducer, done ); // $ExpectError - reduceRightAsync( true, acc, reducer, done ); // $ExpectError - reduceRightAsync( {}, acc, reducer, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a predicate argument which is not a predicate function... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 2, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, false, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, true, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 'abc', done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, [], done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a done callback argument which is not a function having a supported signature... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 2 ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, false ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, true ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 'abc' ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, {} ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, [] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const acc = { 'sum': 0 }; - reduceRightAsync(); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, reducer, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - reduceRightAsync.factory( reducer ); // $ExpectType FactoryFunction - reduceRightAsync.factory( { 'series': true }, reducer ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - reduceRightAsync.factory( [], reducer ); // $ExpectError - reduceRightAsync.factory( 123, reducer ); // $ExpectError - reduceRightAsync.factory( 'abc', reducer ); // $ExpectError - reduceRightAsync.factory( false, reducer ); // $ExpectError - reduceRightAsync.factory( true, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not a predicate function... -{ - reduceRightAsync.factory( {} ); // $ExpectError - reduceRightAsync.factory( true ); // $ExpectError - reduceRightAsync.factory( false ); // $ExpectError - reduceRightAsync.factory( {}, 123 ); // $ExpectError - reduceRightAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1( 12, acc, done ); // $ExpectError - fcn1( true, acc, done ); // $ExpectError - fcn1( false, acc, done ); // $ExpectError - fcn1( {}, acc, done ); // $ExpectError - - fcn1( [ 3000, 2500, 1000 ], acc, 12 ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, true ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, false ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, '5' ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, {} ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, [] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1(); // $ExpectError - fcn1( [ 3000, 2500, 1000 ] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - reduceRightAsync.factory( { 'limit': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': true }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': false }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - reduceRightAsync.factory( { 'series': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': 12 }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - reduceRightAsync.factory(); // $ExpectError - reduceRightAsync.factory( {}, reducer, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index dd64345..0000000 --- a/examples/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var resolve = require( 'path' ).resolve; -var readFile = require( '@stdlib/fs-read-file' ); -var reduceRightAsync = require( './../lib' ); - -var files = [ - resolve( __dirname, '..', 'package.json' ), - resolve( __dirname, '..', 'README.md' ) -]; - -function done( error, acc ) { - if ( error ) { - throw error; - } - console.log( acc.count ); -} - -function read( acc, file, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( file, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( null, acc ); - } - acc.count += 1; - next( null, acc ); - } -} - -var acc = { - 'count': 0 -}; -reduceRightAsync( files, acc, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 28e0a36..f6cba5d 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..234a485 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as c}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";function m(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var d=m(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function f(e,m){var f,u,p;if(f={},arguments.length>1){if(u=function(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("1RZ2o","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!c(e.limit))?new TypeError(r("1RZ3P","limit",e.limit)):null):new TypeError(r("1RZ2V",t))}(f,e),u)throw u;p=m}else p=e;if(!t(p))throw new TypeError(r("1RZ3q",p));return void 0===f.series&&void 0===f.limit&&(f.series=!0),f.series?f.limit=1:f.limit||(f.limit=s),function(e,s,n){if(!i(e))throw new TypeError(r("1RZAh",e));if(!t(n))throw new TypeError(r("1RZ3q",n));return function(e,t,i,r,s){var n,o,l,c,m,f;if(c=e.length,d("Collection length: %d",c),0===c)return d("Finished processing a collection."),s(null,t);for(l=c0&&u();function u(){function s(e,i){if(!o){if(e)return o=!0,p(e);d("Accumulator: %s",JSON.stringify(i)),t=i,p()}}d("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function p(e){return e?(d("Encountered an error: %s",e.message),s(e)):(d("Processed %d of %d collection elements.",n+=1,c),m>0?u():n===c?(d("Finished processing a collection."),s(null,t)):void 0)}}(e,s,f,p,(function(e,t){if(e)return n(e);n(null,t)}))}}function u(e,t,i,r,s){if(arguments.length<5)return f(i)(e,t,r);f(i,r)(e,t,s)}e(u,"factory",f);export{u as default,f as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..e11f2cb --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/limit.js","../lib/factory.js","../lib/validate.js","../lib/main.js","../lib/index.js"],"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 logger = require( 'debug' );\n\n\n// VARIABLES //\n\nvar debug = logger( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RZ3q', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '1RZAh', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RZ3q', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '1RZ2V', 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( '1RZ2o', '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( '1RZ3P', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["debug","logger","factory","options","fcn","opts","err","f","arguments","length","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","validate","isFunction","PINF","collection","initial","done","isCollection","acc","count","flg","lim","len","idx","i","next","cb","error","result","clbk","JSON","stringify","call","message","reduceRightAsync","setReadOnly","main"],"mappings":";;81CA2BIA,uDAAQC,CAAQ,4BCoEpB,SAASC,EAASC,EAASC,GAC1B,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAA,EACFG,UAAUC,OAAS,EAAI,CAE3B,GADAH,EChDF,SAAmBD,EAAMF,GACxB,OAAMO,EAAUP,IAGXQ,EAAYR,EAAS,aACzBE,EAAKO,QAAUT,EAAQS,SAEnBD,EAAYR,EAAS,YACzBE,EAAKQ,OAASV,EAAQU,QAChBC,EAAWT,EAAKQ,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUX,EAAKQ,SAGnDF,EAAYR,EAAS,WACzBE,EAAKY,MAAQd,EAAQc,OACfC,EAAmBb,EAAKY,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASX,EAAKY,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASb,GAkBzC,CD4BQgB,CAAUd,EAAMF,GACjBG,EACJ,MAAMA,EAEPC,EAAIH,CACN,MACEG,EAAIJ,EAEL,IAAMiB,EAAYb,GACjB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAUvC,YARqB,IAAhBF,EAAKQ,aAAoC,IAAfR,EAAKY,QACnCZ,EAAKQ,QAAS,GAEVR,EAAKQ,OACTR,EAAKY,MAAQ,EACDZ,EAAKY,QACjBZ,EAAKY,MAAQI,GAed,SAA2BC,EAAYC,EAASC,GAC/C,IAAMC,EAAcH,GACnB,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,IAAMF,EAAYI,GACjB,MAAM,IAAIT,UAAWC,EAAQ,QAASQ,IAEvC,ODhGF,SAAgBF,EAAYI,EAAKrB,EAAMD,EAAKoB,GAC3C,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMR,EAAWb,OACjBT,EAAO,wBAAyB8B,GAEnB,IAARA,EAEJ,OADA9B,EAAO,qCACAwB,EAAM,KAAME,GAYpB,IATCG,EADIC,EAAMzB,EAAKY,MACTa,EAEAzB,EAAKY,MAEZjB,EAAO,wBAAyB6B,GAChC7B,EAAO,0BAA2BI,EAAIK,QAEtCkB,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVE,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKR,EAAL,CAIA,GAAKO,EAEJ,OADAP,GAAM,EACCS,EAAMF,GAEdnC,EAAO,kBAAmBsC,KAAKC,UAAWH,IAC1CV,EAAMU,EACNC,GAPC,CAQD,CA5BDrC,EAAO,6BADP+B,GAAO,EACmCO,KAAKC,UAAWjB,EAAYS,KAClD,IAAf3B,EAAIK,OACRL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOG,GACtB,IAAf9B,EAAIK,OACfL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKG,GAErD9B,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKT,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJnC,EAAO,2BAA4BmC,EAAMM,SAClCjB,EAAMW,KAGdnC,EAAO,0CADP2B,GAAS,EACgDG,GACpDC,EAAM,EACHE,IAEHN,IAAUG,GACd9B,EAAO,qCACAwB,EAAM,KAAME,SAFpB,EAIA,CACF,CCKST,CAAOK,EAAYC,EAASlB,EAAME,GAUzC,SAAe4B,EAAOT,GACrB,GAAKS,EACJ,OAAOX,EAAMW,GAEdX,EAAM,KAAME,EACZ,GACD,CACF,CE1EA,SAASgB,EAAkBpB,EAAYC,EAASpB,EAASC,EAAKoB,GAC7D,GAAKhB,UAAUC,OAAS,EACvB,OAAOP,EAASC,EAATD,CAAoBoB,EAAYC,EAASnB,GAEjDF,EAASC,EAASC,EAAlBF,CAAyBoB,EAAYC,EAASC,EAC/C,CClBAmB,EAAAC,EAAA,UAAA1C"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index e107128..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,164 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var validate = require( './validate.js' ); -var limit = require( './limit.js' ); - - -// MAIN // - -/** -* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} last argument must be a function -* @returns {Function} function which invokes the provided function once for each element in a collection -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error, data ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var opts = { -* 'series': false -* }; -* -* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: -* var reduceRightAsync = factory( opts, read ); -* -* // Create a collection over which to iterate: -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* // Define a callback which handles errors: -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* // Run `read` for each element in `files`: -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, done ); -*/ -function factory( options, fcn ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = fcn; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '1RZ3q', f ) ); - } - if ( opts.series === void 0 && opts.limit === void 0 ) { - opts.series = true; - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return reduceRightAsync; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * @private - * @param {Collection} collection - input collection - * @param {*} initial - initial value - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be a collection - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function reduceRightAsync( collection, initial, done ) { - if ( !isCollection( collection ) ) { - throw new TypeError( format( '1RZAh', collection ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '1RZ3q', done ) ); - } - return limit( collection, initial, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {*} [acc] - accumulated value - * @returns {void} - */ - function clbk( error, acc ) { - if ( error ) { - return done( error ); - } - done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ae657ff..0000000 --- a/lib/index.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* @module @stdlib/utils-async-reduce-right -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' ); -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/limit.js b/lib/limit.js deleted file mode 100644 index cdb60af..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); - - -// VARIABLES // - -var debug = logger( 'reduce-right-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each element in a collection, limiting the number of concurrently pending functions and iterating from right to left. -* -* @private -* @param {Collection} collection - input collection -* @param {*} acc - initial value -* @param {Options} opts - function options -* @param {*} [opts.thisArg] - execution context -* @param {PositiveInteger} [opts.limit] - maximum number of pending function invocations -* @param {Function} fcn - function to invoke -* @param {Callback} done - function to invoke upon completion or upon encountering an error -* @returns {void} -*/ -function limit( collection, acc, opts, fcn, done ) { - var count; - var flg; - var lim; - var len; - var idx; - var i; - - len = collection.length; - debug( 'Collection length: %d', len ); - - if ( len === 0 ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - count = 0; - idx = len; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all collection elements... - if ( idx > 0 ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next element in a collection. - * - * @private - */ - function next() { - idx -= 1; - debug( 'Collection element %d: %s.', idx, JSON.stringify( collection[ idx ] ) ); - if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], cb ); - } else if ( fcn.length === 4 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, cb ); - } else { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len - } - /** - * Callback invoked once a provided function finishes processing a collection element. - * - * @private - * @param {*} [error] - error - * @param {*} [result] - accumulation result - * @returns {void} - */ - function cb( error, result ) { - if ( flg ) { - // Prevent further processing of collection elements: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Accumulator: %s', JSON.stringify( result ) ); - acc = result; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next collection element. - * - * @private - * @param {*} [error] - error - * @returns {void} - */ - function clbk( error ) { - if ( error ) { - debug( 'Encountered an error: %s', error.message ); - return done( error ); - } - count += 1; - debug( 'Processed %d of %d collection elements.', count, len ); - if ( idx > 0 ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index c8b0d0f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param {Collection} collection - input collection -* @param {*} initial - initial value -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} second-to-last argument must be a function -* @throws {TypeError} last argument must be a function -* @returns {void} -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -function reduceRightAsync( collection, initial, options, fcn, done ) { - if ( arguments.length < 5 ) { - return factory( options )( collection, initial, fcn ); - } - factory( options, fcn )( collection, initial, done ); -} - - -// EXPORTS // - -module.exports = reduceRightAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 0c666fe..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @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 -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'thisArg': {}, -* 'series': false, -* 'limit': 10 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '1RZ2V', options ) ); - } - if ( hasOwnProp( options, 'thisArg' ) ) { - opts.thisArg = options.thisArg; - } - if ( hasOwnProp( options, 'series' ) ) { - opts.series = options.series; - if ( !isBoolean( opts.series ) ) { - return new TypeError( format( '1RZ2o', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '1RZ3P', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 0c316c5..563c57c 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,44 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-collection": "^0.2.2", - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/assert-is-positive-integer": "^0.2.2", - "@stdlib/constants-float64-pinf": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "debug": "^2.6.9", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/constants-float64-eps": "^0.2.2", - "@stdlib/fs-read-file": "^0.2.2", - "@stdlib/utils-noop": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..69bcdc8 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 8244931..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1095 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( {}, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, next ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - factory( opts, next ); - }; - } -}); - -tape( 'the function returns a function (no options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided a collection (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a collection (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (1 argument)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (2 arguments)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with five arguments', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn() { - var value; - var next; - var acc; - var k; - - acc = arguments[ 0 ]; - value = arguments[ 1 ]; - k = arguments[ 2 ]; - next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( k, i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the returned function supports processing collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements concurrently', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 100, 250, 300 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements sequentially (limit = 1)', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of collection elements which are processed at any one time', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 250, 300, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 250, 100, 300 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var reduceRightAsync; - var arr; - - reduceRightAsync = factory( fcn ); - arr = []; - - reduceRightAsync( arr, 0, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var reduceRightAsync; - var obj; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = []; - obj = {}; - reduceRightAsync( arr, obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - i = 0; - - reduceRightAsync( arr, {}, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, acc ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the returned function does not skip empty elements', function test( t ) { - var reduceRightAsync; - var expected; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index f273a40..0000000 --- a/test/test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof reduceRightAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 1893240..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1035 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a collection', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (no options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, next, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, 0 ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - reduceRightAsync( [ 1, 2, 3 ], 0, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (1 argument)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (2 arguments)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with five arguments', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn() { - var next; - var acc; - var v; - - next = arguments[ 4 ]; - acc = arguments[ 0 ]; - v = arguments[ 1 ]; - - i -= 1; - j += 1; - - t.strictEqual( v, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, v ); - - function onTimeout() { - acc.sum += v; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'by default, the function processes collection elements sequentially', function test( t ) { - var values; - var count; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements concurrently', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 100, 250, 300 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': true - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially (limit = 1)', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var arr; - var ctx; - - arr = [ 3, 2, 1 ]; - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 3, 2, 1 ]; - opts = { - 'series': true - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 250, 100, 300 ]; - opts = { - 'limit': 2 - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var arr = []; - reduceRightAsync( arr, 0, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var arr = []; - var obj = {}; - - reduceRightAsync( arr, obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - arr = [ 3, 2, 1 ]; - i = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, value ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the function does not skip empty elements', function test( t ) { - var expected; - var arr; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, fcn, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 7660838..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,181 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `limit` option which is not a positive integer', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - -5, - 0, - 3.14, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'limit': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `series` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'series': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function accepts any value for the `thisArg` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'thisArg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err, null, 'returns null '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'thisArg': {}, - 'series': false, - 'limit': 10 - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From 32116ec770225f9ba532f3477d7120d2e1b0eea3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 04:51:57 +0000 Subject: [PATCH 136/147] Transform error messages --- lib/factory.js | 8 ++++---- lib/validate.js | 8 ++++---- package.json | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 1125052..e107128 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -22,7 +22,7 @@ var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var PINF = require( '@stdlib/constants-float64-pinf' ); var validate = require( './validate.js' ); var limit = require( './limit.js' ); @@ -109,7 +109,7 @@ function factory( options, fcn ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '1RZ3q', f ) ); } if ( opts.series === void 0 && opts.limit === void 0 ) { opts.series = true; @@ -134,10 +134,10 @@ function factory( options, fcn ) { */ function reduceRightAsync( collection, initial, done ) { if ( !isCollection( collection ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a collection. Value: `%s`.', collection ) ); + throw new TypeError( format( '1RZAh', collection ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '1RZ3q', done ) ); } return limit( collection, initial, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index 9ba927e..0c666fe 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,7 +54,7 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '1RZ2V', options ) ); } if ( hasOwnProp( options, 'thisArg' ) ) { opts.thisArg = options.thisArg; @@ -62,13 +62,13 @@ function validate( opts, options ) { if ( hasOwnProp( options, 'series' ) ) { opts.series = options.series; if ( !isBoolean( opts.series ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'series', opts.series ) ); + return new TypeError( format( '1RZ2o', 'series', opts.series ) ); } } if ( hasOwnProp( options, 'limit' ) ) { opts.limit = options.limit; if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'limit', opts.limit ) ); + return new TypeError( format( '1RZ3P', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index 48d1408..fa2e069 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-plain-object": "^0.2.2", "@stdlib/assert-is-positive-integer": "^0.2.2", "@stdlib/constants-float64-pinf": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", "debug": "^2.6.9", From 7e090015cfff0d8d151c00fc62f405f9527c5d73 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 08:26:47 +0000 Subject: [PATCH 137/147] Remove files --- index.d.ts | 410 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5257 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index f6cba5d..0000000 --- a/index.d.ts +++ /dev/null @@ -1,410 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Execution context. - */ - thisArg?: ThisParameterType>; - - /** - * The maximum number of pending invocations at any one time. - */ - limit?: number; - - /** - * Boolean indicating whether to sequentially invoke the reducer function for each `collection` element. If `true`, the function sets `options.limit=1`. Default: true. - */ - series?: boolean; -} - -/** -* Callback function. -*/ -type Nullary = () => void; - -/** -* Callback function. -* -* @param error - encountered error or null -*/ -type Unary = ( error: Error | null ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Binary = ( error: Error | null, accumulator: U ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param next - a callback to be invoked after processing a collection `value` -*/ -type TernaryReducer = ( this: V, accumulator: U, value: T, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuaternaryReducer = ( this: V, accumulator: U, value: T, index: number, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuinaryReducer = ( this: V, accumulator: U, value: T, index: number, collection: Collection, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type Reducer = TernaryReducer | QuaternaryReducer | QuinaryReducer; - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result. -* -* @param collection - input collection -* @param initial - initial value -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( collection: Collection, initial: U, done: Callback ) => void; - -/** -* Interface for `reduceRightAsync`. -*/ -interface ReduceRightAsync { - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, {}, read, done ); - */ - ( collection: Collection, initial: U, options: Options, reducer: Reducer, done: Callback ): void; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, read, done ); - */ - ( collection: Collection, initial: U, reducer: Reducer, done: Callback ): void; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @throws must provide valid options - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var opts = { - * 'series': false - * }; - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( opts, read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( options: Options, reducer: Reducer ): FactoryFunction; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param reducer - function to invoke for each element in a collection - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( reducer: Reducer ): FactoryFunction; -} - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param collection - input collection -* @param initial - initial value -* @param options - function options -* @param options.thisArg - execution context -* @param options.limit - maximum number of pending invocations at any one time -* @param 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 (default: true) -* @param reducer - function to invoke for each element in a collection -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -declare var reduceRightAsync: ReduceRightAsync; - - -// EXPORTS // - -export = reduceRightAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 234a485..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as c}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";function m(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var d=m(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function f(e,m){var f,u,p;if(f={},arguments.length>1){if(u=function(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("1RZ2o","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!c(e.limit))?new TypeError(r("1RZ3P","limit",e.limit)):null):new TypeError(r("1RZ2V",t))}(f,e),u)throw u;p=m}else p=e;if(!t(p))throw new TypeError(r("1RZ3q",p));return void 0===f.series&&void 0===f.limit&&(f.series=!0),f.series?f.limit=1:f.limit||(f.limit=s),function(e,s,n){if(!i(e))throw new TypeError(r("1RZAh",e));if(!t(n))throw new TypeError(r("1RZ3q",n));return function(e,t,i,r,s){var n,o,l,c,m,f;if(c=e.length,d("Collection length: %d",c),0===c)return d("Finished processing a collection."),s(null,t);for(l=c0&&u();function u(){function s(e,i){if(!o){if(e)return o=!0,p(e);d("Accumulator: %s",JSON.stringify(i)),t=i,p()}}d("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function p(e){return e?(d("Encountered an error: %s",e.message),s(e)):(d("Processed %d of %d collection elements.",n+=1,c),m>0?u():n===c?(d("Finished processing a collection."),s(null,t)):void 0)}}(e,s,f,p,(function(e,t){if(e)return n(e);n(null,t)}))}}function u(e,t,i,r,s){if(arguments.length<5)return f(i)(e,t,r);f(i,r)(e,t,s)}e(u,"factory",f);export{u as default,f as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index e11f2cb..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/limit.js","../lib/factory.js","../lib/validate.js","../lib/main.js","../lib/index.js"],"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 logger = require( 'debug' );\n\n\n// VARIABLES //\n\nvar debug = logger( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RZ3q', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '1RZAh', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RZ3q', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '1RZ2V', 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( '1RZ2o', '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( '1RZ3P', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["debug","logger","factory","options","fcn","opts","err","f","arguments","length","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","validate","isFunction","PINF","collection","initial","done","isCollection","acc","count","flg","lim","len","idx","i","next","cb","error","result","clbk","JSON","stringify","call","message","reduceRightAsync","setReadOnly","main"],"mappings":";;81CA2BIA,uDAAQC,CAAQ,4BCoEpB,SAASC,EAASC,EAASC,GAC1B,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAA,EACFG,UAAUC,OAAS,EAAI,CAE3B,GADAH,EChDF,SAAmBD,EAAMF,GACxB,OAAMO,EAAUP,IAGXQ,EAAYR,EAAS,aACzBE,EAAKO,QAAUT,EAAQS,SAEnBD,EAAYR,EAAS,YACzBE,EAAKQ,OAASV,EAAQU,QAChBC,EAAWT,EAAKQ,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUX,EAAKQ,SAGnDF,EAAYR,EAAS,WACzBE,EAAKY,MAAQd,EAAQc,OACfC,EAAmBb,EAAKY,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASX,EAAKY,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASb,GAkBzC,CD4BQgB,CAAUd,EAAMF,GACjBG,EACJ,MAAMA,EAEPC,EAAIH,CACN,MACEG,EAAIJ,EAEL,IAAMiB,EAAYb,GACjB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAUvC,YARqB,IAAhBF,EAAKQ,aAAoC,IAAfR,EAAKY,QACnCZ,EAAKQ,QAAS,GAEVR,EAAKQ,OACTR,EAAKY,MAAQ,EACDZ,EAAKY,QACjBZ,EAAKY,MAAQI,GAed,SAA2BC,EAAYC,EAASC,GAC/C,IAAMC,EAAcH,GACnB,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,IAAMF,EAAYI,GACjB,MAAM,IAAIT,UAAWC,EAAQ,QAASQ,IAEvC,ODhGF,SAAgBF,EAAYI,EAAKrB,EAAMD,EAAKoB,GAC3C,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMR,EAAWb,OACjBT,EAAO,wBAAyB8B,GAEnB,IAARA,EAEJ,OADA9B,EAAO,qCACAwB,EAAM,KAAME,GAYpB,IATCG,EADIC,EAAMzB,EAAKY,MACTa,EAEAzB,EAAKY,MAEZjB,EAAO,wBAAyB6B,GAChC7B,EAAO,0BAA2BI,EAAIK,QAEtCkB,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVE,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKR,EAAL,CAIA,GAAKO,EAEJ,OADAP,GAAM,EACCS,EAAMF,GAEdnC,EAAO,kBAAmBsC,KAAKC,UAAWH,IAC1CV,EAAMU,EACNC,GAPC,CAQD,CA5BDrC,EAAO,6BADP+B,GAAO,EACmCO,KAAKC,UAAWjB,EAAYS,KAClD,IAAf3B,EAAIK,OACRL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOG,GACtB,IAAf9B,EAAIK,OACfL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKG,GAErD9B,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKT,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJnC,EAAO,2BAA4BmC,EAAMM,SAClCjB,EAAMW,KAGdnC,EAAO,0CADP2B,GAAS,EACgDG,GACpDC,EAAM,EACHE,IAEHN,IAAUG,GACd9B,EAAO,qCACAwB,EAAM,KAAME,SAFpB,EAIA,CACF,CCKST,CAAOK,EAAYC,EAASlB,EAAME,GAUzC,SAAe4B,EAAOT,GACrB,GAAKS,EACJ,OAAOX,EAAMW,GAEdX,EAAM,KAAME,EACZ,GACD,CACF,CE1EA,SAASgB,EAAkBpB,EAAYC,EAASpB,EAASC,EAAKoB,GAC7D,GAAKhB,UAAUC,OAAS,EACvB,OAAOP,EAASC,EAATD,CAAoBoB,EAAYC,EAASnB,GAEjDF,EAASC,EAASC,EAAlBF,CAAyBoB,EAAYC,EAASC,EAC/C,CClBAmB,EAAAC,EAAA,UAAA1C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 69bcdc8..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From f65b1f537b75b25fd8b56d25279d54b443016243 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 08:26:59 +0000 Subject: [PATCH 138/147] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 245 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.factory.js | 73 - benchmark/benchmark.js | 160 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 224 - docs/types/test.ts | 166 - examples/index.js | 55 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 164 - lib/index.js | 77 - lib/limit.js | 142 - lib/main.js | 95 - lib/validate.js | 80 - package.json | 65 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 1095 ---- test/test.js | 38 - test/test.main.js | 1035 ---- test/test.validate.js | 181 - 51 files changed, 4873 insertions(+), 7316 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/limit.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index f62bdfa..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-12-01T03:38:17.841Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1e08946..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 5358060..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index fa37f2d..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '37 1 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -460,7 +457,7 @@ reduceRightAsync( files, acc, read, done ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -531,11 +528,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right +[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right/tree/esm -[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce +[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index b155fd2..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var reduceRightAsync; - var arr; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - reduceRightAsync = factory( onItem ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - var acc; - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index af5c346..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var reduceRightAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=false', function benchmark( b ) { - var opts; - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'series': false - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var arr; - var len; - var acc; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'limit': 3 - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b8adcd2..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right" -%% click B href "https://github.com/stdlib-js/utils-async-reduce-right/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-reduce-right/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-reduce-right/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-reduce-right/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right -[production-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-async-reduce-right/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-async-reduce-right/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-async-reduce-right/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 47a072e..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import reduceRightAsync from '../docs/types/index'; -export = reduceRightAsync; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 530ca4d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var c=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var x=c(function(U,O){ -var R=require('@stdlib/assert-is-plain-object/dist'),h=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,k=require('@stdlib/assert-is-positive-integer/dist').isPrimitive,d=require('@stdlib/error-tools-fmtprodmsg/dist');function I(e,r){return R(r)?(h(r,"thisArg")&&(e.thisArg=r.thisArg),h(r,"series")&&(e.series=r.series,!j(e.series))?new TypeError(d('1RZ2o',"series",e.series)):h(r,"limit")&&(e.limit=r.limit,!k(e.limit))?new TypeError(d('1RZ3P',"limit",e.limit)):null):new TypeError(d('1RZ2V',r));}O.exports=I -});var P=c(function(W,E){ -var J=require("debug"),a=J("reduce-right-async:limit");function L(e,r,i,t,s){var f,m,v,n,u,g;if(n=e.length,a("Collection length: %d",n),n===0)return a("Finished processing a collection."),s(null,r);for(n0&&o();function o(){u-=1,a("Collection element %d: %s.",u,JSON.stringify(e[u])),t.length===3?t.call(i.thisArg,r,e[u],l):t.length===4?t.call(i.thisArg,r,e[u],u,l):t.call(i.thisArg,r,e[u],u,e,l);function l(w,A){if(!m){if(w)return m=!0,b(w);a("Accumulator: %s",JSON.stringify(A)),r=A,b()}}}function b(l){if(l)return a("Encountered an error: %s",l.message),s(l);if(f+=1,a("Processed %d of %d collection elements.",f,n),u>0)return o();if(f===n)return a("Finished processing a collection."),s(null,r)}}E.exports=L -});var q=c(function(X,F){ -var T=require('@stdlib/assert-is-function/dist'),S=require('@stdlib/assert-is-collection/dist'),y=require('@stdlib/error-tools-fmtprodmsg/dist'),B=require('@stdlib/constants-float64-pinf/dist'),z=x(),D=P();function G(e,r){var i,t,s;if(i={},arguments.length>1){if(t=z(i,e),t)throw t;s=r}else s=e;if(!T(s))throw new TypeError(y('1RZ3q',s));return i.series===void 0&&i.limit===void 0&&(i.series=!0),i.series?i.limit=1:i.limit||(i.limit=B),f;function f(m,v,n){if(!S(m))throw new TypeError(y('1RZAh',m));if(!T(n))throw new TypeError(y('1RZ3q',n));return D(m,v,i,s,u);function u(g,o){if(g)return n(g);n(null,o)}}}F.exports=G -});var N=c(function(Y,C){ -var p=q();function H(e,r,i,t,s){if(arguments.length<5)return p(i)(e,r,t);p(i,t)(e,r,s)}C.exports=H -});var K=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),V=N(),M=q();K(V,"factory",M);module.exports=V; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index acb9d67..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/limit.js", "../lib/factory.js", "../lib/main.js", "../lib/index.js"], - "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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\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 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 to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\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 === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, 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 ( !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, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\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* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nmodule.exports = reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' );\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, 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"], - "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,0BAA2B,EAkB/C,SAASE,EAAOC,EAAYC,EAAKC,EAAMC,EAAKC,EAAO,CAClD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMR,EAAW,OACjBF,EAAO,wBAAyBU,CAAI,EAE/BA,IAAQ,EACZ,OAAAV,EAAO,mCAAoC,EACpCM,EAAM,KAAMH,CAAI,EAYxB,IAVKO,EAAMN,EAAK,MACfK,EAAMC,EAEND,EAAML,EAAK,MAEZJ,EAAO,wBAAyBS,CAAI,EACpCT,EAAO,0BAA2BK,EAAI,MAAO,EAE7CE,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVE,EAAK,EAQP,SAASA,GAAO,CACfF,GAAO,EACPX,EAAO,6BAA8BW,EAAK,KAAK,UAAWT,EAAYS,CAAI,CAAE,CAAE,EACzEN,EAAI,SAAW,EACnBA,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGG,CAAG,EACxCT,EAAI,SAAW,EAC1BA,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGA,EAAKG,CAAG,EAExDT,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGA,EAAKT,EAAYY,CAAG,EAUrE,SAASA,EAAIC,EAAOC,EAAS,CAC5B,GAAK,CAAAR,EAIL,IAAKO,EACJ,OAAAP,EAAM,GACCS,EAAMF,CAAM,EAEpBf,EAAO,kBAAmB,KAAK,UAAWgB,CAAO,CAAE,EACnDb,EAAMa,EACNC,EAAK,EACN,CACD,CASA,SAASA,EAAMF,EAAQ,CACtB,GAAKA,EACJ,OAAAf,EAAO,2BAA4Be,EAAM,OAAQ,EAC1CT,EAAMS,CAAM,EAIpB,GAFAR,GAAS,EACTP,EAAO,0CAA2CO,EAAOG,CAAI,EACxDC,EAAM,EACV,OAAOE,EAAK,EAEb,GAAKN,IAAUG,EACd,OAAAV,EAAO,mCAAoC,EACpCM,EAAM,KAAMH,CAAI,CAEzB,CACD,CAKAL,EAAO,QAAUG,IC7IjB,IAAAiB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,gCAAiC,EACjDC,EAAW,IACXC,EAAQ,IAoEZ,SAASC,EAASC,EAASC,EAAM,CAChC,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,CAACP,EAAYW,CAAE,EACnB,MAAM,IAAI,UAAWT,EAAQ,mEAAoES,CAAE,CAAE,EAEtG,OAAKF,EAAK,SAAW,QAAUA,EAAK,QAAU,SAC7CA,EAAK,OAAS,IAEVA,EAAK,OACTA,EAAK,MAAQ,EACDA,EAAK,QACjBA,EAAK,MAAQN,GAEPS,EAaP,SAASA,EAAkBC,EAAYC,EAASC,EAAO,CACtD,GAAK,CAACd,EAAcY,CAAW,EAC9B,MAAM,IAAI,UAAWX,EAAQ,sEAAuEW,CAAW,CAAE,EAElH,GAAK,CAACb,EAAYe,CAAK,EACtB,MAAM,IAAI,UAAWb,EAAQ,mEAAoEa,CAAK,CAAE,EAEzG,OAAOV,EAAOQ,EAAYC,EAASL,EAAME,EAAGK,CAAK,EAUjD,SAASA,EAAMC,EAAOC,EAAM,CAC3B,GAAKD,EACJ,OAAOF,EAAME,CAAM,EAEpBF,EAAM,KAAMG,CAAI,CACjB,CACD,CACD,CAKAnB,EAAO,QAAUO,ICnKjB,IAAAa,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,IA8Dd,SAASC,EAAkBC,EAAYC,EAASC,EAASC,EAAKC,EAAO,CACpE,GAAK,UAAU,OAAS,EACvB,OAAON,EAASI,CAAQ,EAAGF,EAAYC,EAASE,CAAI,EAErDL,EAASI,EAASC,CAAI,EAAGH,EAAYC,EAASG,CAAK,CACpD,CAKAP,EAAO,QAAUE,IC9BjB,IAAIM,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "isPositiveInteger", "format", "validate", "opts", "options", "require_limit", "__commonJSMin", "exports", "module", "logger", "debug", "limit", "collection", "acc", "opts", "fcn", "done", "count", "flg", "lim", "len", "idx", "i", "next", "cb", "error", "result", "clbk", "require_factory", "__commonJSMin", "exports", "module", "isFunction", "isCollection", "format", "PINF", "validate", "limit", "factory", "options", "fcn", "opts", "err", "f", "reduceRightAsync", "collection", "initial", "done", "clbk", "error", "acc", "require_main", "__commonJSMin", "exports", "module", "factory", "reduceRightAsync", "collection", "initial", "options", "fcn", "done", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 078b453..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,224 +0,0 @@ - -{{alias}}( collection, initial, [options,] reducer, done ) - Applies a function against an accumulator and each element in a collection - and returns the accumulated result, iterating from right to left. - - When invoked, `reducer` is provided a maximum of five arguments: - - - accumulator: accumulated value. - - value: collection value. - - index: collection index. - - collection: the input collection. - - next: a callback to be invoked after processing a collection `value`. - - The actual number of provided arguments depends on function length. If - `reducer` accepts three arguments, `reducer` is provided: - - - accumulator - - value - - next - - If `reducer` accepts four arguments, `reducer` is provided: - - - accumulator - - value - - index - - next - - For every other `reducer` signature, `reducer` is provided all five - arguments. - - The `next` callback accepts two arguments: - - - error: error argument. - - accumulator: accumulated value. - - If a provided function calls the `next` callback with a truthy `error` - argument, the function suspends execution and immediately calls the `done` - callback for subsequent `error` handling. - - Execution is *not* guaranteed to be asynchronous. To guarantee asynchrony, - 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`). - - The function does not support dynamic collection resizing. - - If provided an empty collection, the function invokes the `done` callback - with the `initial` value as the second argument. - - The function does not skip `undefined` elements. - - When processing collection elements concurrently, *beware* of race - conditions when updating an accumulator. This is especially true when an - accumulator is a primitive (e.g., a number). In general, prefer object - accumulators. - - Parameters - ---------- - collection: Array|TypedArray|Object - Input collection over which to iterate. If provided an object, the - object must be array-like (excluding strings and functions). - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - reducer: Function - The function to invoke for each element in a collection. - - done: Function - A callback invoked either upon processing all collection elements or - upon encountering an error. - - Examples - -------- - // Basic usage: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, fcn, done ) - 3000 - 2500 - 1000 - 6500 - - // Limit number of concurrent invocations: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'limit': 2 }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 2500 - 3000 - 1000 - 6500 - - // Process concurrently: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'series': false }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 1000 - 2500 - 3000 - 6500 - - -{{alias}}.factory( [options,] fcn ) - Returns a function which applies a function against an accumulator and each - element in a collection and returns the accumulated result, iterating from - right to left. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - fcn: Function - The function to invoke for each element in a collection. - - Returns - ------- - out: Function - A function which invokes a function for each element in a collection. - - Examples - -------- - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > var opts = { 'series': false }; - > var f = {{alias}}.factory( opts, fcn ); - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > f( arr, acc, done ) - 1000 - 2500 - 3000 - 6500 - > acc = { 'sum': 0 }; - > arr = [ 1000, 1500, 2000 ]; - > f( arr, acc, done ) - 1000 - 1500 - 2000 - 4500 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0455864..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,166 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unsafe-assignment */ - -import reduceRightAsync = require( './index' ); - -const reducer = ( acc: any, value: number, index: number, next: Function ) => { - acc.sum += value; - if ( index === void 0 ) { - throw new Error( '`index` is missing.' ); - } - next( null, acc ); -}; - -const done = ( error: Error | null, acc: any ) => { - if ( error ) { - throw error; - } - if ( acc === void 0 ) { - throw new Error( '`acc` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( 2, acc, reducer, done ); // $ExpectError - reduceRightAsync( false, acc, reducer, done ); // $ExpectError - reduceRightAsync( true, acc, reducer, done ); // $ExpectError - reduceRightAsync( {}, acc, reducer, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a predicate argument which is not a predicate function... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 2, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, false, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, true, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 'abc', done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, [], done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a done callback argument which is not a function having a supported signature... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 2 ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, false ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, true ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 'abc' ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, {} ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, [] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const acc = { 'sum': 0 }; - reduceRightAsync(); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, reducer, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - reduceRightAsync.factory( reducer ); // $ExpectType FactoryFunction - reduceRightAsync.factory( { 'series': true }, reducer ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - reduceRightAsync.factory( [], reducer ); // $ExpectError - reduceRightAsync.factory( 123, reducer ); // $ExpectError - reduceRightAsync.factory( 'abc', reducer ); // $ExpectError - reduceRightAsync.factory( false, reducer ); // $ExpectError - reduceRightAsync.factory( true, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not a predicate function... -{ - reduceRightAsync.factory( {} ); // $ExpectError - reduceRightAsync.factory( true ); // $ExpectError - reduceRightAsync.factory( false ); // $ExpectError - reduceRightAsync.factory( {}, 123 ); // $ExpectError - reduceRightAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1( 12, acc, done ); // $ExpectError - fcn1( true, acc, done ); // $ExpectError - fcn1( false, acc, done ); // $ExpectError - fcn1( {}, acc, done ); // $ExpectError - - fcn1( [ 3000, 2500, 1000 ], acc, 12 ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, true ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, false ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, '5' ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, {} ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, [] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1(); // $ExpectError - fcn1( [ 3000, 2500, 1000 ] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - reduceRightAsync.factory( { 'limit': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': true }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': false }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - reduceRightAsync.factory( { 'series': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': 12 }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - reduceRightAsync.factory(); // $ExpectError - reduceRightAsync.factory( {}, reducer, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index dd64345..0000000 --- a/examples/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var resolve = require( 'path' ).resolve; -var readFile = require( '@stdlib/fs-read-file' ); -var reduceRightAsync = require( './../lib' ); - -var files = [ - resolve( __dirname, '..', 'package.json' ), - resolve( __dirname, '..', 'README.md' ) -]; - -function done( error, acc ) { - if ( error ) { - throw error; - } - console.log( acc.count ); -} - -function read( acc, file, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( file, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( null, acc ); - } - acc.count += 1; - next( null, acc ); - } -} - -var acc = { - 'count': 0 -}; -reduceRightAsync( files, acc, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 28e0a36..f6cba5d 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..234a485 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as c}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";function m(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var d=m(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function f(e,m){var f,u,p;if(f={},arguments.length>1){if(u=function(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("1RZ2o","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!c(e.limit))?new TypeError(r("1RZ3P","limit",e.limit)):null):new TypeError(r("1RZ2V",t))}(f,e),u)throw u;p=m}else p=e;if(!t(p))throw new TypeError(r("1RZ3q",p));return void 0===f.series&&void 0===f.limit&&(f.series=!0),f.series?f.limit=1:f.limit||(f.limit=s),function(e,s,n){if(!i(e))throw new TypeError(r("1RZAh",e));if(!t(n))throw new TypeError(r("1RZ3q",n));return function(e,t,i,r,s){var n,o,l,c,m,f;if(c=e.length,d("Collection length: %d",c),0===c)return d("Finished processing a collection."),s(null,t);for(l=c0&&u();function u(){function s(e,i){if(!o){if(e)return o=!0,p(e);d("Accumulator: %s",JSON.stringify(i)),t=i,p()}}d("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function p(e){return e?(d("Encountered an error: %s",e.message),s(e)):(d("Processed %d of %d collection elements.",n+=1,c),m>0?u():n===c?(d("Finished processing a collection."),s(null,t)):void 0)}}(e,s,f,p,(function(e,t){if(e)return n(e);n(null,t)}))}}function u(e,t,i,r,s){if(arguments.length<5)return f(i)(e,t,r);f(i,r)(e,t,s)}e(u,"factory",f);export{u as default,f as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..e11f2cb --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/limit.js","../lib/factory.js","../lib/validate.js","../lib/main.js","../lib/index.js"],"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 logger = require( 'debug' );\n\n\n// VARIABLES //\n\nvar debug = logger( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RZ3q', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '1RZAh', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RZ3q', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '1RZ2V', 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( '1RZ2o', '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( '1RZ3P', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["debug","logger","factory","options","fcn","opts","err","f","arguments","length","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","validate","isFunction","PINF","collection","initial","done","isCollection","acc","count","flg","lim","len","idx","i","next","cb","error","result","clbk","JSON","stringify","call","message","reduceRightAsync","setReadOnly","main"],"mappings":";;81CA2BIA,uDAAQC,CAAQ,4BCoEpB,SAASC,EAASC,EAASC,GAC1B,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAA,EACFG,UAAUC,OAAS,EAAI,CAE3B,GADAH,EChDF,SAAmBD,EAAMF,GACxB,OAAMO,EAAUP,IAGXQ,EAAYR,EAAS,aACzBE,EAAKO,QAAUT,EAAQS,SAEnBD,EAAYR,EAAS,YACzBE,EAAKQ,OAASV,EAAQU,QAChBC,EAAWT,EAAKQ,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUX,EAAKQ,SAGnDF,EAAYR,EAAS,WACzBE,EAAKY,MAAQd,EAAQc,OACfC,EAAmBb,EAAKY,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASX,EAAKY,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASb,GAkBzC,CD4BQgB,CAAUd,EAAMF,GACjBG,EACJ,MAAMA,EAEPC,EAAIH,CACN,MACEG,EAAIJ,EAEL,IAAMiB,EAAYb,GACjB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAUvC,YARqB,IAAhBF,EAAKQ,aAAoC,IAAfR,EAAKY,QACnCZ,EAAKQ,QAAS,GAEVR,EAAKQ,OACTR,EAAKY,MAAQ,EACDZ,EAAKY,QACjBZ,EAAKY,MAAQI,GAed,SAA2BC,EAAYC,EAASC,GAC/C,IAAMC,EAAcH,GACnB,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,IAAMF,EAAYI,GACjB,MAAM,IAAIT,UAAWC,EAAQ,QAASQ,IAEvC,ODhGF,SAAgBF,EAAYI,EAAKrB,EAAMD,EAAKoB,GAC3C,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMR,EAAWb,OACjBT,EAAO,wBAAyB8B,GAEnB,IAARA,EAEJ,OADA9B,EAAO,qCACAwB,EAAM,KAAME,GAYpB,IATCG,EADIC,EAAMzB,EAAKY,MACTa,EAEAzB,EAAKY,MAEZjB,EAAO,wBAAyB6B,GAChC7B,EAAO,0BAA2BI,EAAIK,QAEtCkB,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVE,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKR,EAAL,CAIA,GAAKO,EAEJ,OADAP,GAAM,EACCS,EAAMF,GAEdnC,EAAO,kBAAmBsC,KAAKC,UAAWH,IAC1CV,EAAMU,EACNC,GAPC,CAQD,CA5BDrC,EAAO,6BADP+B,GAAO,EACmCO,KAAKC,UAAWjB,EAAYS,KAClD,IAAf3B,EAAIK,OACRL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOG,GACtB,IAAf9B,EAAIK,OACfL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKG,GAErD9B,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKT,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJnC,EAAO,2BAA4BmC,EAAMM,SAClCjB,EAAMW,KAGdnC,EAAO,0CADP2B,GAAS,EACgDG,GACpDC,EAAM,EACHE,IAEHN,IAAUG,GACd9B,EAAO,qCACAwB,EAAM,KAAME,SAFpB,EAIA,CACF,CCKST,CAAOK,EAAYC,EAASlB,EAAME,GAUzC,SAAe4B,EAAOT,GACrB,GAAKS,EACJ,OAAOX,EAAMW,GAEdX,EAAM,KAAME,EACZ,GACD,CACF,CE1EA,SAASgB,EAAkBpB,EAAYC,EAASpB,EAASC,EAAKoB,GAC7D,GAAKhB,UAAUC,OAAS,EACvB,OAAOP,EAASC,EAATD,CAAoBoB,EAAYC,EAASnB,GAEjDF,EAASC,EAASC,EAAlBF,CAAyBoB,EAAYC,EAASC,EAC/C,CClBAmB,EAAAC,EAAA,UAAA1C"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index e107128..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,164 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var validate = require( './validate.js' ); -var limit = require( './limit.js' ); - - -// MAIN // - -/** -* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} last argument must be a function -* @returns {Function} function which invokes the provided function once for each element in a collection -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error, data ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var opts = { -* 'series': false -* }; -* -* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: -* var reduceRightAsync = factory( opts, read ); -* -* // Create a collection over which to iterate: -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* // Define a callback which handles errors: -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* // Run `read` for each element in `files`: -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, done ); -*/ -function factory( options, fcn ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = fcn; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '1RZ3q', f ) ); - } - if ( opts.series === void 0 && opts.limit === void 0 ) { - opts.series = true; - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return reduceRightAsync; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * @private - * @param {Collection} collection - input collection - * @param {*} initial - initial value - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be a collection - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function reduceRightAsync( collection, initial, done ) { - if ( !isCollection( collection ) ) { - throw new TypeError( format( '1RZAh', collection ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '1RZ3q', done ) ); - } - return limit( collection, initial, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {*} [acc] - accumulated value - * @returns {void} - */ - function clbk( error, acc ) { - if ( error ) { - return done( error ); - } - done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ae657ff..0000000 --- a/lib/index.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* @module @stdlib/utils-async-reduce-right -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' ); -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/limit.js b/lib/limit.js deleted file mode 100644 index cdb60af..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); - - -// VARIABLES // - -var debug = logger( 'reduce-right-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each element in a collection, limiting the number of concurrently pending functions and iterating from right to left. -* -* @private -* @param {Collection} collection - input collection -* @param {*} acc - initial value -* @param {Options} opts - function options -* @param {*} [opts.thisArg] - execution context -* @param {PositiveInteger} [opts.limit] - maximum number of pending function invocations -* @param {Function} fcn - function to invoke -* @param {Callback} done - function to invoke upon completion or upon encountering an error -* @returns {void} -*/ -function limit( collection, acc, opts, fcn, done ) { - var count; - var flg; - var lim; - var len; - var idx; - var i; - - len = collection.length; - debug( 'Collection length: %d', len ); - - if ( len === 0 ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - count = 0; - idx = len; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all collection elements... - if ( idx > 0 ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next element in a collection. - * - * @private - */ - function next() { - idx -= 1; - debug( 'Collection element %d: %s.', idx, JSON.stringify( collection[ idx ] ) ); - if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], cb ); - } else if ( fcn.length === 4 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, cb ); - } else { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len - } - /** - * Callback invoked once a provided function finishes processing a collection element. - * - * @private - * @param {*} [error] - error - * @param {*} [result] - accumulation result - * @returns {void} - */ - function cb( error, result ) { - if ( flg ) { - // Prevent further processing of collection elements: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Accumulator: %s', JSON.stringify( result ) ); - acc = result; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next collection element. - * - * @private - * @param {*} [error] - error - * @returns {void} - */ - function clbk( error ) { - if ( error ) { - debug( 'Encountered an error: %s', error.message ); - return done( error ); - } - count += 1; - debug( 'Processed %d of %d collection elements.', count, len ); - if ( idx > 0 ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index c8b0d0f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param {Collection} collection - input collection -* @param {*} initial - initial value -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} second-to-last argument must be a function -* @throws {TypeError} last argument must be a function -* @returns {void} -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -function reduceRightAsync( collection, initial, options, fcn, done ) { - if ( arguments.length < 5 ) { - return factory( options )( collection, initial, fcn ); - } - factory( options, fcn )( collection, initial, done ); -} - - -// EXPORTS // - -module.exports = reduceRightAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 0c666fe..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @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 -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'thisArg': {}, -* 'series': false, -* 'limit': 10 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '1RZ2V', options ) ); - } - if ( hasOwnProp( options, 'thisArg' ) ) { - opts.thisArg = options.thisArg; - } - if ( hasOwnProp( options, 'series' ) ) { - opts.series = options.series; - if ( !isBoolean( opts.series ) ) { - return new TypeError( format( '1RZ2o', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '1RZ3P', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index fa2e069..563c57c 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,44 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-collection": "^0.2.2", - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/assert-is-positive-integer": "^0.2.2", - "@stdlib/constants-float64-pinf": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "debug": "^2.6.9", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/constants-float64-eps": "^0.2.2", - "@stdlib/fs-read-file": "^0.2.2", - "@stdlib/utils-noop": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..69bcdc8 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 8244931..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1095 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( {}, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, next ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - factory( opts, next ); - }; - } -}); - -tape( 'the function returns a function (no options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided a collection (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a collection (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (1 argument)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (2 arguments)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with five arguments', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn() { - var value; - var next; - var acc; - var k; - - acc = arguments[ 0 ]; - value = arguments[ 1 ]; - k = arguments[ 2 ]; - next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( k, i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the returned function supports processing collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements concurrently', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 100, 250, 300 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements sequentially (limit = 1)', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of collection elements which are processed at any one time', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 250, 300, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 250, 100, 300 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var reduceRightAsync; - var arr; - - reduceRightAsync = factory( fcn ); - arr = []; - - reduceRightAsync( arr, 0, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var reduceRightAsync; - var obj; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = []; - obj = {}; - reduceRightAsync( arr, obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - i = 0; - - reduceRightAsync( arr, {}, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, acc ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the returned function does not skip empty elements', function test( t ) { - var reduceRightAsync; - var expected; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index f273a40..0000000 --- a/test/test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof reduceRightAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 1893240..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1035 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a collection', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (no options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, next, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, 0 ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - reduceRightAsync( [ 1, 2, 3 ], 0, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (1 argument)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (2 arguments)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with five arguments', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn() { - var next; - var acc; - var v; - - next = arguments[ 4 ]; - acc = arguments[ 0 ]; - v = arguments[ 1 ]; - - i -= 1; - j += 1; - - t.strictEqual( v, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, v ); - - function onTimeout() { - acc.sum += v; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'by default, the function processes collection elements sequentially', function test( t ) { - var values; - var count; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements concurrently', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 100, 250, 300 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': true - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially (limit = 1)', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var arr; - var ctx; - - arr = [ 3, 2, 1 ]; - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 3, 2, 1 ]; - opts = { - 'series': true - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 250, 100, 300 ]; - opts = { - 'limit': 2 - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var arr = []; - reduceRightAsync( arr, 0, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var arr = []; - var obj = {}; - - reduceRightAsync( arr, obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - arr = [ 3, 2, 1 ]; - i = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, value ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the function does not skip empty elements', function test( t ) { - var expected; - var arr; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, fcn, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 7660838..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,181 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `limit` option which is not a positive integer', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - -5, - 0, - 3.14, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'limit': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `series` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'series': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function accepts any value for the `thisArg` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'thisArg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err, null, 'returns null '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'thisArg': {}, - 'series': false, - 'limit': 10 - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From 07e04dd0943226d98b286a4723847e32e10b5e9d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 9 Dec 2024 02:21:48 +0000 Subject: [PATCH 139/147] Transform error messages --- lib/factory.js | 8 ++++---- lib/validate.js | 8 ++++---- package.json | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 1125052..e107128 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -22,7 +22,7 @@ var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var PINF = require( '@stdlib/constants-float64-pinf' ); var validate = require( './validate.js' ); var limit = require( './limit.js' ); @@ -109,7 +109,7 @@ function factory( options, fcn ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '1RZ3q', f ) ); } if ( opts.series === void 0 && opts.limit === void 0 ) { opts.series = true; @@ -134,10 +134,10 @@ function factory( options, fcn ) { */ function reduceRightAsync( collection, initial, done ) { if ( !isCollection( collection ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a collection. Value: `%s`.', collection ) ); + throw new TypeError( format( '1RZAh', collection ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '1RZ3q', done ) ); } return limit( collection, initial, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index 9ba927e..0c666fe 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,7 +54,7 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '1RZ2V', options ) ); } if ( hasOwnProp( options, 'thisArg' ) ) { opts.thisArg = options.thisArg; @@ -62,13 +62,13 @@ function validate( opts, options ) { if ( hasOwnProp( options, 'series' ) ) { opts.series = options.series; if ( !isBoolean( opts.series ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'series', opts.series ) ); + return new TypeError( format( '1RZ2o', 'series', opts.series ) ); } } if ( hasOwnProp( options, 'limit' ) ) { opts.limit = options.limit; if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'limit', opts.limit ) ); + return new TypeError( format( '1RZ3P', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index 48d1408..fa2e069 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-plain-object": "^0.2.2", "@stdlib/assert-is-positive-integer": "^0.2.2", "@stdlib/constants-float64-pinf": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", "debug": "^2.6.9", From 3c23c929698a257bbb4db78ad5e575a9df721483 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 9 Dec 2024 02:45:49 +0000 Subject: [PATCH 140/147] Remove files --- index.d.ts | 410 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5257 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index f6cba5d..0000000 --- a/index.d.ts +++ /dev/null @@ -1,410 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Execution context. - */ - thisArg?: ThisParameterType>; - - /** - * The maximum number of pending invocations at any one time. - */ - limit?: number; - - /** - * Boolean indicating whether to sequentially invoke the reducer function for each `collection` element. If `true`, the function sets `options.limit=1`. Default: true. - */ - series?: boolean; -} - -/** -* Callback function. -*/ -type Nullary = () => void; - -/** -* Callback function. -* -* @param error - encountered error or null -*/ -type Unary = ( error: Error | null ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Binary = ( error: Error | null, accumulator: U ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param next - a callback to be invoked after processing a collection `value` -*/ -type TernaryReducer = ( this: V, accumulator: U, value: T, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuaternaryReducer = ( this: V, accumulator: U, value: T, index: number, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuinaryReducer = ( this: V, accumulator: U, value: T, index: number, collection: Collection, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type Reducer = TernaryReducer | QuaternaryReducer | QuinaryReducer; - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result. -* -* @param collection - input collection -* @param initial - initial value -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( collection: Collection, initial: U, done: Callback ) => void; - -/** -* Interface for `reduceRightAsync`. -*/ -interface ReduceRightAsync { - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, {}, read, done ); - */ - ( collection: Collection, initial: U, options: Options, reducer: Reducer, done: Callback ): void; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, read, done ); - */ - ( collection: Collection, initial: U, reducer: Reducer, done: Callback ): void; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @throws must provide valid options - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var opts = { - * 'series': false - * }; - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( opts, read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( options: Options, reducer: Reducer ): FactoryFunction; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param reducer - function to invoke for each element in a collection - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( reducer: Reducer ): FactoryFunction; -} - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param collection - input collection -* @param initial - initial value -* @param options - function options -* @param options.thisArg - execution context -* @param options.limit - maximum number of pending invocations at any one time -* @param 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 (default: true) -* @param reducer - function to invoke for each element in a collection -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -declare var reduceRightAsync: ReduceRightAsync; - - -// EXPORTS // - -export = reduceRightAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 234a485..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as c}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";function m(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var d=m(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function f(e,m){var f,u,p;if(f={},arguments.length>1){if(u=function(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("1RZ2o","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!c(e.limit))?new TypeError(r("1RZ3P","limit",e.limit)):null):new TypeError(r("1RZ2V",t))}(f,e),u)throw u;p=m}else p=e;if(!t(p))throw new TypeError(r("1RZ3q",p));return void 0===f.series&&void 0===f.limit&&(f.series=!0),f.series?f.limit=1:f.limit||(f.limit=s),function(e,s,n){if(!i(e))throw new TypeError(r("1RZAh",e));if(!t(n))throw new TypeError(r("1RZ3q",n));return function(e,t,i,r,s){var n,o,l,c,m,f;if(c=e.length,d("Collection length: %d",c),0===c)return d("Finished processing a collection."),s(null,t);for(l=c0&&u();function u(){function s(e,i){if(!o){if(e)return o=!0,p(e);d("Accumulator: %s",JSON.stringify(i)),t=i,p()}}d("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function p(e){return e?(d("Encountered an error: %s",e.message),s(e)):(d("Processed %d of %d collection elements.",n+=1,c),m>0?u():n===c?(d("Finished processing a collection."),s(null,t)):void 0)}}(e,s,f,p,(function(e,t){if(e)return n(e);n(null,t)}))}}function u(e,t,i,r,s){if(arguments.length<5)return f(i)(e,t,r);f(i,r)(e,t,s)}e(u,"factory",f);export{u as default,f as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index e11f2cb..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/limit.js","../lib/factory.js","../lib/validate.js","../lib/main.js","../lib/index.js"],"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 logger = require( 'debug' );\n\n\n// VARIABLES //\n\nvar debug = logger( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RZ3q', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '1RZAh', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RZ3q', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '1RZ2V', 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( '1RZ2o', '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( '1RZ3P', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["debug","logger","factory","options","fcn","opts","err","f","arguments","length","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","validate","isFunction","PINF","collection","initial","done","isCollection","acc","count","flg","lim","len","idx","i","next","cb","error","result","clbk","JSON","stringify","call","message","reduceRightAsync","setReadOnly","main"],"mappings":";;81CA2BIA,uDAAQC,CAAQ,4BCoEpB,SAASC,EAASC,EAASC,GAC1B,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAA,EACFG,UAAUC,OAAS,EAAI,CAE3B,GADAH,EChDF,SAAmBD,EAAMF,GACxB,OAAMO,EAAUP,IAGXQ,EAAYR,EAAS,aACzBE,EAAKO,QAAUT,EAAQS,SAEnBD,EAAYR,EAAS,YACzBE,EAAKQ,OAASV,EAAQU,QAChBC,EAAWT,EAAKQ,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUX,EAAKQ,SAGnDF,EAAYR,EAAS,WACzBE,EAAKY,MAAQd,EAAQc,OACfC,EAAmBb,EAAKY,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASX,EAAKY,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASb,GAkBzC,CD4BQgB,CAAUd,EAAMF,GACjBG,EACJ,MAAMA,EAEPC,EAAIH,CACN,MACEG,EAAIJ,EAEL,IAAMiB,EAAYb,GACjB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAUvC,YARqB,IAAhBF,EAAKQ,aAAoC,IAAfR,EAAKY,QACnCZ,EAAKQ,QAAS,GAEVR,EAAKQ,OACTR,EAAKY,MAAQ,EACDZ,EAAKY,QACjBZ,EAAKY,MAAQI,GAed,SAA2BC,EAAYC,EAASC,GAC/C,IAAMC,EAAcH,GACnB,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,IAAMF,EAAYI,GACjB,MAAM,IAAIT,UAAWC,EAAQ,QAASQ,IAEvC,ODhGF,SAAgBF,EAAYI,EAAKrB,EAAMD,EAAKoB,GAC3C,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMR,EAAWb,OACjBT,EAAO,wBAAyB8B,GAEnB,IAARA,EAEJ,OADA9B,EAAO,qCACAwB,EAAM,KAAME,GAYpB,IATCG,EADIC,EAAMzB,EAAKY,MACTa,EAEAzB,EAAKY,MAEZjB,EAAO,wBAAyB6B,GAChC7B,EAAO,0BAA2BI,EAAIK,QAEtCkB,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVE,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKR,EAAL,CAIA,GAAKO,EAEJ,OADAP,GAAM,EACCS,EAAMF,GAEdnC,EAAO,kBAAmBsC,KAAKC,UAAWH,IAC1CV,EAAMU,EACNC,GAPC,CAQD,CA5BDrC,EAAO,6BADP+B,GAAO,EACmCO,KAAKC,UAAWjB,EAAYS,KAClD,IAAf3B,EAAIK,OACRL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOG,GACtB,IAAf9B,EAAIK,OACfL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKG,GAErD9B,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKT,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJnC,EAAO,2BAA4BmC,EAAMM,SAClCjB,EAAMW,KAGdnC,EAAO,0CADP2B,GAAS,EACgDG,GACpDC,EAAM,EACHE,IAEHN,IAAUG,GACd9B,EAAO,qCACAwB,EAAM,KAAME,SAFpB,EAIA,CACF,CCKST,CAAOK,EAAYC,EAASlB,EAAME,GAUzC,SAAe4B,EAAOT,GACrB,GAAKS,EACJ,OAAOX,EAAMW,GAEdX,EAAM,KAAME,EACZ,GACD,CACF,CE1EA,SAASgB,EAAkBpB,EAAYC,EAASpB,EAASC,EAAKoB,GAC7D,GAAKhB,UAAUC,OAAS,EACvB,OAAOP,EAASC,EAATD,CAAoBoB,EAAYC,EAASnB,GAEjDF,EAASC,EAASC,EAAlBF,CAAyBoB,EAAYC,EAASC,EAC/C,CClBAmB,EAAAC,EAAA,UAAA1C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 69bcdc8..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From cd2f00c56a0b0210fa7ff14f44e69b0b0cc9da72 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 9 Dec 2024 02:46:01 +0000 Subject: [PATCH 141/147] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 245 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.factory.js | 73 - benchmark/benchmark.js | 160 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 224 - docs/types/test.ts | 166 - examples/index.js | 55 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 164 - lib/index.js | 77 - lib/limit.js | 142 - lib/main.js | 95 - lib/validate.js | 80 - package.json | 65 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 1095 ---- test/test.js | 38 - test/test.main.js | 1035 ---- test/test.validate.js | 181 - 51 files changed, 4873 insertions(+), 7316 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/limit.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 593c23a..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-12-09T02:12:57.692Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1e08946..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 5358060..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index fa37f2d..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '37 1 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -460,7 +457,7 @@ reduceRightAsync( files, acc, read, done ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -531,11 +528,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right +[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right/tree/esm -[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce +[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index b155fd2..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var reduceRightAsync; - var arr; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - reduceRightAsync = factory( onItem ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - var acc; - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index af5c346..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var reduceRightAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=false', function benchmark( b ) { - var opts; - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'series': false - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var arr; - var len; - var acc; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'limit': 3 - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b8adcd2..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right" -%% click B href "https://github.com/stdlib-js/utils-async-reduce-right/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-reduce-right/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-reduce-right/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-reduce-right/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right -[production-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-async-reduce-right/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-async-reduce-right/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-async-reduce-right/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 47a072e..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import reduceRightAsync from '../docs/types/index'; -export = reduceRightAsync; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 530ca4d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var c=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var x=c(function(U,O){ -var R=require('@stdlib/assert-is-plain-object/dist'),h=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,k=require('@stdlib/assert-is-positive-integer/dist').isPrimitive,d=require('@stdlib/error-tools-fmtprodmsg/dist');function I(e,r){return R(r)?(h(r,"thisArg")&&(e.thisArg=r.thisArg),h(r,"series")&&(e.series=r.series,!j(e.series))?new TypeError(d('1RZ2o',"series",e.series)):h(r,"limit")&&(e.limit=r.limit,!k(e.limit))?new TypeError(d('1RZ3P',"limit",e.limit)):null):new TypeError(d('1RZ2V',r));}O.exports=I -});var P=c(function(W,E){ -var J=require("debug"),a=J("reduce-right-async:limit");function L(e,r,i,t,s){var f,m,v,n,u,g;if(n=e.length,a("Collection length: %d",n),n===0)return a("Finished processing a collection."),s(null,r);for(n0&&o();function o(){u-=1,a("Collection element %d: %s.",u,JSON.stringify(e[u])),t.length===3?t.call(i.thisArg,r,e[u],l):t.length===4?t.call(i.thisArg,r,e[u],u,l):t.call(i.thisArg,r,e[u],u,e,l);function l(w,A){if(!m){if(w)return m=!0,b(w);a("Accumulator: %s",JSON.stringify(A)),r=A,b()}}}function b(l){if(l)return a("Encountered an error: %s",l.message),s(l);if(f+=1,a("Processed %d of %d collection elements.",f,n),u>0)return o();if(f===n)return a("Finished processing a collection."),s(null,r)}}E.exports=L -});var q=c(function(X,F){ -var T=require('@stdlib/assert-is-function/dist'),S=require('@stdlib/assert-is-collection/dist'),y=require('@stdlib/error-tools-fmtprodmsg/dist'),B=require('@stdlib/constants-float64-pinf/dist'),z=x(),D=P();function G(e,r){var i,t,s;if(i={},arguments.length>1){if(t=z(i,e),t)throw t;s=r}else s=e;if(!T(s))throw new TypeError(y('1RZ3q',s));return i.series===void 0&&i.limit===void 0&&(i.series=!0),i.series?i.limit=1:i.limit||(i.limit=B),f;function f(m,v,n){if(!S(m))throw new TypeError(y('1RZAh',m));if(!T(n))throw new TypeError(y('1RZ3q',n));return D(m,v,i,s,u);function u(g,o){if(g)return n(g);n(null,o)}}}F.exports=G -});var N=c(function(Y,C){ -var p=q();function H(e,r,i,t,s){if(arguments.length<5)return p(i)(e,r,t);p(i,t)(e,r,s)}C.exports=H -});var K=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),V=N(),M=q();K(V,"factory",M);module.exports=V; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index acb9d67..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/limit.js", "../lib/factory.js", "../lib/main.js", "../lib/index.js"], - "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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\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 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 to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\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 === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, 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 ( !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, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\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* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nmodule.exports = reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' );\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, 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"], - "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,0BAA2B,EAkB/C,SAASE,EAAOC,EAAYC,EAAKC,EAAMC,EAAKC,EAAO,CAClD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMR,EAAW,OACjBF,EAAO,wBAAyBU,CAAI,EAE/BA,IAAQ,EACZ,OAAAV,EAAO,mCAAoC,EACpCM,EAAM,KAAMH,CAAI,EAYxB,IAVKO,EAAMN,EAAK,MACfK,EAAMC,EAEND,EAAML,EAAK,MAEZJ,EAAO,wBAAyBS,CAAI,EACpCT,EAAO,0BAA2BK,EAAI,MAAO,EAE7CE,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVE,EAAK,EAQP,SAASA,GAAO,CACfF,GAAO,EACPX,EAAO,6BAA8BW,EAAK,KAAK,UAAWT,EAAYS,CAAI,CAAE,CAAE,EACzEN,EAAI,SAAW,EACnBA,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGG,CAAG,EACxCT,EAAI,SAAW,EAC1BA,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGA,EAAKG,CAAG,EAExDT,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGA,EAAKT,EAAYY,CAAG,EAUrE,SAASA,EAAIC,EAAOC,EAAS,CAC5B,GAAK,CAAAR,EAIL,IAAKO,EACJ,OAAAP,EAAM,GACCS,EAAMF,CAAM,EAEpBf,EAAO,kBAAmB,KAAK,UAAWgB,CAAO,CAAE,EACnDb,EAAMa,EACNC,EAAK,EACN,CACD,CASA,SAASA,EAAMF,EAAQ,CACtB,GAAKA,EACJ,OAAAf,EAAO,2BAA4Be,EAAM,OAAQ,EAC1CT,EAAMS,CAAM,EAIpB,GAFAR,GAAS,EACTP,EAAO,0CAA2CO,EAAOG,CAAI,EACxDC,EAAM,EACV,OAAOE,EAAK,EAEb,GAAKN,IAAUG,EACd,OAAAV,EAAO,mCAAoC,EACpCM,EAAM,KAAMH,CAAI,CAEzB,CACD,CAKAL,EAAO,QAAUG,IC7IjB,IAAAiB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,gCAAiC,EACjDC,EAAW,IACXC,EAAQ,IAoEZ,SAASC,EAASC,EAASC,EAAM,CAChC,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,CAACP,EAAYW,CAAE,EACnB,MAAM,IAAI,UAAWT,EAAQ,mEAAoES,CAAE,CAAE,EAEtG,OAAKF,EAAK,SAAW,QAAUA,EAAK,QAAU,SAC7CA,EAAK,OAAS,IAEVA,EAAK,OACTA,EAAK,MAAQ,EACDA,EAAK,QACjBA,EAAK,MAAQN,GAEPS,EAaP,SAASA,EAAkBC,EAAYC,EAASC,EAAO,CACtD,GAAK,CAACd,EAAcY,CAAW,EAC9B,MAAM,IAAI,UAAWX,EAAQ,sEAAuEW,CAAW,CAAE,EAElH,GAAK,CAACb,EAAYe,CAAK,EACtB,MAAM,IAAI,UAAWb,EAAQ,mEAAoEa,CAAK,CAAE,EAEzG,OAAOV,EAAOQ,EAAYC,EAASL,EAAME,EAAGK,CAAK,EAUjD,SAASA,EAAMC,EAAOC,EAAM,CAC3B,GAAKD,EACJ,OAAOF,EAAME,CAAM,EAEpBF,EAAM,KAAMG,CAAI,CACjB,CACD,CACD,CAKAnB,EAAO,QAAUO,ICnKjB,IAAAa,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,IA8Dd,SAASC,EAAkBC,EAAYC,EAASC,EAASC,EAAKC,EAAO,CACpE,GAAK,UAAU,OAAS,EACvB,OAAON,EAASI,CAAQ,EAAGF,EAAYC,EAASE,CAAI,EAErDL,EAASI,EAASC,CAAI,EAAGH,EAAYC,EAASG,CAAK,CACpD,CAKAP,EAAO,QAAUE,IC9BjB,IAAIM,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "isPositiveInteger", "format", "validate", "opts", "options", "require_limit", "__commonJSMin", "exports", "module", "logger", "debug", "limit", "collection", "acc", "opts", "fcn", "done", "count", "flg", "lim", "len", "idx", "i", "next", "cb", "error", "result", "clbk", "require_factory", "__commonJSMin", "exports", "module", "isFunction", "isCollection", "format", "PINF", "validate", "limit", "factory", "options", "fcn", "opts", "err", "f", "reduceRightAsync", "collection", "initial", "done", "clbk", "error", "acc", "require_main", "__commonJSMin", "exports", "module", "factory", "reduceRightAsync", "collection", "initial", "options", "fcn", "done", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 078b453..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,224 +0,0 @@ - -{{alias}}( collection, initial, [options,] reducer, done ) - Applies a function against an accumulator and each element in a collection - and returns the accumulated result, iterating from right to left. - - When invoked, `reducer` is provided a maximum of five arguments: - - - accumulator: accumulated value. - - value: collection value. - - index: collection index. - - collection: the input collection. - - next: a callback to be invoked after processing a collection `value`. - - The actual number of provided arguments depends on function length. If - `reducer` accepts three arguments, `reducer` is provided: - - - accumulator - - value - - next - - If `reducer` accepts four arguments, `reducer` is provided: - - - accumulator - - value - - index - - next - - For every other `reducer` signature, `reducer` is provided all five - arguments. - - The `next` callback accepts two arguments: - - - error: error argument. - - accumulator: accumulated value. - - If a provided function calls the `next` callback with a truthy `error` - argument, the function suspends execution and immediately calls the `done` - callback for subsequent `error` handling. - - Execution is *not* guaranteed to be asynchronous. To guarantee asynchrony, - 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`). - - The function does not support dynamic collection resizing. - - If provided an empty collection, the function invokes the `done` callback - with the `initial` value as the second argument. - - The function does not skip `undefined` elements. - - When processing collection elements concurrently, *beware* of race - conditions when updating an accumulator. This is especially true when an - accumulator is a primitive (e.g., a number). In general, prefer object - accumulators. - - Parameters - ---------- - collection: Array|TypedArray|Object - Input collection over which to iterate. If provided an object, the - object must be array-like (excluding strings and functions). - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - reducer: Function - The function to invoke for each element in a collection. - - done: Function - A callback invoked either upon processing all collection elements or - upon encountering an error. - - Examples - -------- - // Basic usage: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, fcn, done ) - 3000 - 2500 - 1000 - 6500 - - // Limit number of concurrent invocations: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'limit': 2 }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 2500 - 3000 - 1000 - 6500 - - // Process concurrently: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'series': false }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 1000 - 2500 - 3000 - 6500 - - -{{alias}}.factory( [options,] fcn ) - Returns a function which applies a function against an accumulator and each - element in a collection and returns the accumulated result, iterating from - right to left. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - fcn: Function - The function to invoke for each element in a collection. - - Returns - ------- - out: Function - A function which invokes a function for each element in a collection. - - Examples - -------- - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > var opts = { 'series': false }; - > var f = {{alias}}.factory( opts, fcn ); - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > f( arr, acc, done ) - 1000 - 2500 - 3000 - 6500 - > acc = { 'sum': 0 }; - > arr = [ 1000, 1500, 2000 ]; - > f( arr, acc, done ) - 1000 - 1500 - 2000 - 4500 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0455864..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,166 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unsafe-assignment */ - -import reduceRightAsync = require( './index' ); - -const reducer = ( acc: any, value: number, index: number, next: Function ) => { - acc.sum += value; - if ( index === void 0 ) { - throw new Error( '`index` is missing.' ); - } - next( null, acc ); -}; - -const done = ( error: Error | null, acc: any ) => { - if ( error ) { - throw error; - } - if ( acc === void 0 ) { - throw new Error( '`acc` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( 2, acc, reducer, done ); // $ExpectError - reduceRightAsync( false, acc, reducer, done ); // $ExpectError - reduceRightAsync( true, acc, reducer, done ); // $ExpectError - reduceRightAsync( {}, acc, reducer, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a predicate argument which is not a predicate function... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 2, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, false, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, true, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 'abc', done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, [], done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a done callback argument which is not a function having a supported signature... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 2 ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, false ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, true ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 'abc' ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, {} ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, [] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const acc = { 'sum': 0 }; - reduceRightAsync(); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, reducer, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - reduceRightAsync.factory( reducer ); // $ExpectType FactoryFunction - reduceRightAsync.factory( { 'series': true }, reducer ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - reduceRightAsync.factory( [], reducer ); // $ExpectError - reduceRightAsync.factory( 123, reducer ); // $ExpectError - reduceRightAsync.factory( 'abc', reducer ); // $ExpectError - reduceRightAsync.factory( false, reducer ); // $ExpectError - reduceRightAsync.factory( true, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not a predicate function... -{ - reduceRightAsync.factory( {} ); // $ExpectError - reduceRightAsync.factory( true ); // $ExpectError - reduceRightAsync.factory( false ); // $ExpectError - reduceRightAsync.factory( {}, 123 ); // $ExpectError - reduceRightAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1( 12, acc, done ); // $ExpectError - fcn1( true, acc, done ); // $ExpectError - fcn1( false, acc, done ); // $ExpectError - fcn1( {}, acc, done ); // $ExpectError - - fcn1( [ 3000, 2500, 1000 ], acc, 12 ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, true ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, false ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, '5' ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, {} ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, [] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1(); // $ExpectError - fcn1( [ 3000, 2500, 1000 ] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - reduceRightAsync.factory( { 'limit': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': true }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': false }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - reduceRightAsync.factory( { 'series': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': 12 }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - reduceRightAsync.factory(); // $ExpectError - reduceRightAsync.factory( {}, reducer, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index dd64345..0000000 --- a/examples/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var resolve = require( 'path' ).resolve; -var readFile = require( '@stdlib/fs-read-file' ); -var reduceRightAsync = require( './../lib' ); - -var files = [ - resolve( __dirname, '..', 'package.json' ), - resolve( __dirname, '..', 'README.md' ) -]; - -function done( error, acc ) { - if ( error ) { - throw error; - } - console.log( acc.count ); -} - -function read( acc, file, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( file, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( null, acc ); - } - acc.count += 1; - next( null, acc ); - } -} - -var acc = { - 'count': 0 -}; -reduceRightAsync( files, acc, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 28e0a36..f6cba5d 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..234a485 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as c}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";function m(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var d=m(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function f(e,m){var f,u,p;if(f={},arguments.length>1){if(u=function(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("1RZ2o","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!c(e.limit))?new TypeError(r("1RZ3P","limit",e.limit)):null):new TypeError(r("1RZ2V",t))}(f,e),u)throw u;p=m}else p=e;if(!t(p))throw new TypeError(r("1RZ3q",p));return void 0===f.series&&void 0===f.limit&&(f.series=!0),f.series?f.limit=1:f.limit||(f.limit=s),function(e,s,n){if(!i(e))throw new TypeError(r("1RZAh",e));if(!t(n))throw new TypeError(r("1RZ3q",n));return function(e,t,i,r,s){var n,o,l,c,m,f;if(c=e.length,d("Collection length: %d",c),0===c)return d("Finished processing a collection."),s(null,t);for(l=c0&&u();function u(){function s(e,i){if(!o){if(e)return o=!0,p(e);d("Accumulator: %s",JSON.stringify(i)),t=i,p()}}d("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function p(e){return e?(d("Encountered an error: %s",e.message),s(e)):(d("Processed %d of %d collection elements.",n+=1,c),m>0?u():n===c?(d("Finished processing a collection."),s(null,t)):void 0)}}(e,s,f,p,(function(e,t){if(e)return n(e);n(null,t)}))}}function u(e,t,i,r,s){if(arguments.length<5)return f(i)(e,t,r);f(i,r)(e,t,s)}e(u,"factory",f);export{u as default,f as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..e11f2cb --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/limit.js","../lib/factory.js","../lib/validate.js","../lib/main.js","../lib/index.js"],"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 logger = require( 'debug' );\n\n\n// VARIABLES //\n\nvar debug = logger( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RZ3q', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '1RZAh', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RZ3q', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '1RZ2V', 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( '1RZ2o', '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( '1RZ3P', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["debug","logger","factory","options","fcn","opts","err","f","arguments","length","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","validate","isFunction","PINF","collection","initial","done","isCollection","acc","count","flg","lim","len","idx","i","next","cb","error","result","clbk","JSON","stringify","call","message","reduceRightAsync","setReadOnly","main"],"mappings":";;81CA2BIA,uDAAQC,CAAQ,4BCoEpB,SAASC,EAASC,EAASC,GAC1B,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAA,EACFG,UAAUC,OAAS,EAAI,CAE3B,GADAH,EChDF,SAAmBD,EAAMF,GACxB,OAAMO,EAAUP,IAGXQ,EAAYR,EAAS,aACzBE,EAAKO,QAAUT,EAAQS,SAEnBD,EAAYR,EAAS,YACzBE,EAAKQ,OAASV,EAAQU,QAChBC,EAAWT,EAAKQ,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUX,EAAKQ,SAGnDF,EAAYR,EAAS,WACzBE,EAAKY,MAAQd,EAAQc,OACfC,EAAmBb,EAAKY,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASX,EAAKY,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASb,GAkBzC,CD4BQgB,CAAUd,EAAMF,GACjBG,EACJ,MAAMA,EAEPC,EAAIH,CACN,MACEG,EAAIJ,EAEL,IAAMiB,EAAYb,GACjB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAUvC,YARqB,IAAhBF,EAAKQ,aAAoC,IAAfR,EAAKY,QACnCZ,EAAKQ,QAAS,GAEVR,EAAKQ,OACTR,EAAKY,MAAQ,EACDZ,EAAKY,QACjBZ,EAAKY,MAAQI,GAed,SAA2BC,EAAYC,EAASC,GAC/C,IAAMC,EAAcH,GACnB,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,IAAMF,EAAYI,GACjB,MAAM,IAAIT,UAAWC,EAAQ,QAASQ,IAEvC,ODhGF,SAAgBF,EAAYI,EAAKrB,EAAMD,EAAKoB,GAC3C,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMR,EAAWb,OACjBT,EAAO,wBAAyB8B,GAEnB,IAARA,EAEJ,OADA9B,EAAO,qCACAwB,EAAM,KAAME,GAYpB,IATCG,EADIC,EAAMzB,EAAKY,MACTa,EAEAzB,EAAKY,MAEZjB,EAAO,wBAAyB6B,GAChC7B,EAAO,0BAA2BI,EAAIK,QAEtCkB,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVE,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKR,EAAL,CAIA,GAAKO,EAEJ,OADAP,GAAM,EACCS,EAAMF,GAEdnC,EAAO,kBAAmBsC,KAAKC,UAAWH,IAC1CV,EAAMU,EACNC,GAPC,CAQD,CA5BDrC,EAAO,6BADP+B,GAAO,EACmCO,KAAKC,UAAWjB,EAAYS,KAClD,IAAf3B,EAAIK,OACRL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOG,GACtB,IAAf9B,EAAIK,OACfL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKG,GAErD9B,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKT,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJnC,EAAO,2BAA4BmC,EAAMM,SAClCjB,EAAMW,KAGdnC,EAAO,0CADP2B,GAAS,EACgDG,GACpDC,EAAM,EACHE,IAEHN,IAAUG,GACd9B,EAAO,qCACAwB,EAAM,KAAME,SAFpB,EAIA,CACF,CCKST,CAAOK,EAAYC,EAASlB,EAAME,GAUzC,SAAe4B,EAAOT,GACrB,GAAKS,EACJ,OAAOX,EAAMW,GAEdX,EAAM,KAAME,EACZ,GACD,CACF,CE1EA,SAASgB,EAAkBpB,EAAYC,EAASpB,EAASC,EAAKoB,GAC7D,GAAKhB,UAAUC,OAAS,EACvB,OAAOP,EAASC,EAATD,CAAoBoB,EAAYC,EAASnB,GAEjDF,EAASC,EAASC,EAAlBF,CAAyBoB,EAAYC,EAASC,EAC/C,CClBAmB,EAAAC,EAAA,UAAA1C"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index e107128..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,164 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var validate = require( './validate.js' ); -var limit = require( './limit.js' ); - - -// MAIN // - -/** -* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} last argument must be a function -* @returns {Function} function which invokes the provided function once for each element in a collection -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error, data ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var opts = { -* 'series': false -* }; -* -* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: -* var reduceRightAsync = factory( opts, read ); -* -* // Create a collection over which to iterate: -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* // Define a callback which handles errors: -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* // Run `read` for each element in `files`: -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, done ); -*/ -function factory( options, fcn ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = fcn; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '1RZ3q', f ) ); - } - if ( opts.series === void 0 && opts.limit === void 0 ) { - opts.series = true; - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return reduceRightAsync; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * @private - * @param {Collection} collection - input collection - * @param {*} initial - initial value - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be a collection - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function reduceRightAsync( collection, initial, done ) { - if ( !isCollection( collection ) ) { - throw new TypeError( format( '1RZAh', collection ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '1RZ3q', done ) ); - } - return limit( collection, initial, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {*} [acc] - accumulated value - * @returns {void} - */ - function clbk( error, acc ) { - if ( error ) { - return done( error ); - } - done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ae657ff..0000000 --- a/lib/index.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* @module @stdlib/utils-async-reduce-right -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' ); -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/limit.js b/lib/limit.js deleted file mode 100644 index cdb60af..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); - - -// VARIABLES // - -var debug = logger( 'reduce-right-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each element in a collection, limiting the number of concurrently pending functions and iterating from right to left. -* -* @private -* @param {Collection} collection - input collection -* @param {*} acc - initial value -* @param {Options} opts - function options -* @param {*} [opts.thisArg] - execution context -* @param {PositiveInteger} [opts.limit] - maximum number of pending function invocations -* @param {Function} fcn - function to invoke -* @param {Callback} done - function to invoke upon completion or upon encountering an error -* @returns {void} -*/ -function limit( collection, acc, opts, fcn, done ) { - var count; - var flg; - var lim; - var len; - var idx; - var i; - - len = collection.length; - debug( 'Collection length: %d', len ); - - if ( len === 0 ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - count = 0; - idx = len; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all collection elements... - if ( idx > 0 ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next element in a collection. - * - * @private - */ - function next() { - idx -= 1; - debug( 'Collection element %d: %s.', idx, JSON.stringify( collection[ idx ] ) ); - if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], cb ); - } else if ( fcn.length === 4 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, cb ); - } else { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len - } - /** - * Callback invoked once a provided function finishes processing a collection element. - * - * @private - * @param {*} [error] - error - * @param {*} [result] - accumulation result - * @returns {void} - */ - function cb( error, result ) { - if ( flg ) { - // Prevent further processing of collection elements: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Accumulator: %s', JSON.stringify( result ) ); - acc = result; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next collection element. - * - * @private - * @param {*} [error] - error - * @returns {void} - */ - function clbk( error ) { - if ( error ) { - debug( 'Encountered an error: %s', error.message ); - return done( error ); - } - count += 1; - debug( 'Processed %d of %d collection elements.', count, len ); - if ( idx > 0 ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index c8b0d0f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param {Collection} collection - input collection -* @param {*} initial - initial value -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} second-to-last argument must be a function -* @throws {TypeError} last argument must be a function -* @returns {void} -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -function reduceRightAsync( collection, initial, options, fcn, done ) { - if ( arguments.length < 5 ) { - return factory( options )( collection, initial, fcn ); - } - factory( options, fcn )( collection, initial, done ); -} - - -// EXPORTS // - -module.exports = reduceRightAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 0c666fe..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @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 -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'thisArg': {}, -* 'series': false, -* 'limit': 10 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '1RZ2V', options ) ); - } - if ( hasOwnProp( options, 'thisArg' ) ) { - opts.thisArg = options.thisArg; - } - if ( hasOwnProp( options, 'series' ) ) { - opts.series = options.series; - if ( !isBoolean( opts.series ) ) { - return new TypeError( format( '1RZ2o', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '1RZ3P', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index fa2e069..563c57c 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,44 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-collection": "^0.2.2", - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/assert-is-positive-integer": "^0.2.2", - "@stdlib/constants-float64-pinf": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "debug": "^2.6.9", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/constants-float64-eps": "^0.2.2", - "@stdlib/fs-read-file": "^0.2.2", - "@stdlib/utils-noop": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..69bcdc8 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 8244931..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1095 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( {}, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, next ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - factory( opts, next ); - }; - } -}); - -tape( 'the function returns a function (no options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided a collection (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a collection (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (1 argument)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (2 arguments)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with five arguments', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn() { - var value; - var next; - var acc; - var k; - - acc = arguments[ 0 ]; - value = arguments[ 1 ]; - k = arguments[ 2 ]; - next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( k, i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the returned function supports processing collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements concurrently', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 100, 250, 300 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements sequentially (limit = 1)', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of collection elements which are processed at any one time', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 250, 300, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 250, 100, 300 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var reduceRightAsync; - var arr; - - reduceRightAsync = factory( fcn ); - arr = []; - - reduceRightAsync( arr, 0, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var reduceRightAsync; - var obj; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = []; - obj = {}; - reduceRightAsync( arr, obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - i = 0; - - reduceRightAsync( arr, {}, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, acc ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the returned function does not skip empty elements', function test( t ) { - var reduceRightAsync; - var expected; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index f273a40..0000000 --- a/test/test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof reduceRightAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 1893240..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1035 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a collection', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (no options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, next, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, 0 ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - reduceRightAsync( [ 1, 2, 3 ], 0, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (1 argument)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (2 arguments)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with five arguments', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn() { - var next; - var acc; - var v; - - next = arguments[ 4 ]; - acc = arguments[ 0 ]; - v = arguments[ 1 ]; - - i -= 1; - j += 1; - - t.strictEqual( v, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, v ); - - function onTimeout() { - acc.sum += v; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'by default, the function processes collection elements sequentially', function test( t ) { - var values; - var count; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements concurrently', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 100, 250, 300 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': true - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially (limit = 1)', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var arr; - var ctx; - - arr = [ 3, 2, 1 ]; - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 3, 2, 1 ]; - opts = { - 'series': true - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 250, 100, 300 ]; - opts = { - 'limit': 2 - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var arr = []; - reduceRightAsync( arr, 0, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var arr = []; - var obj = {}; - - reduceRightAsync( arr, obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - arr = [ 3, 2, 1 ]; - i = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, value ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the function does not skip empty elements', function test( t ) { - var expected; - var arr; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, fcn, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 7660838..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,181 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `limit` option which is not a positive integer', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - -5, - 0, - 3.14, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'limit': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `series` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'series': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function accepts any value for the `thisArg` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'thisArg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err, null, 'returns null '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'thisArg': {}, - 'series': false, - 'limit': 10 - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From cfacbe329cba0926797041d08a4c6ed5b3e255a5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 3 Feb 2025 00:45:05 +0000 Subject: [PATCH 142/147] Transform error messages --- lib/factory.js | 8 ++++---- lib/validate.js | 8 ++++---- package.json | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 1125052..e107128 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -22,7 +22,7 @@ var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var PINF = require( '@stdlib/constants-float64-pinf' ); var validate = require( './validate.js' ); var limit = require( './limit.js' ); @@ -109,7 +109,7 @@ function factory( options, fcn ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '1RZ3q', f ) ); } if ( opts.series === void 0 && opts.limit === void 0 ) { opts.series = true; @@ -134,10 +134,10 @@ function factory( options, fcn ) { */ function reduceRightAsync( collection, initial, done ) { if ( !isCollection( collection ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a collection. Value: `%s`.', collection ) ); + throw new TypeError( format( '1RZAh', collection ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '1RZ3q', done ) ); } return limit( collection, initial, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index 9ba927e..0c666fe 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,7 +54,7 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '1RZ2V', options ) ); } if ( hasOwnProp( options, 'thisArg' ) ) { opts.thisArg = options.thisArg; @@ -62,13 +62,13 @@ function validate( opts, options ) { if ( hasOwnProp( options, 'series' ) ) { opts.series = options.series; if ( !isBoolean( opts.series ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'series', opts.series ) ); + return new TypeError( format( '1RZ2o', 'series', opts.series ) ); } } if ( hasOwnProp( options, 'limit' ) ) { opts.limit = options.limit; if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'limit', opts.limit ) ); + return new TypeError( format( '1RZ3P', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index 48d1408..fa2e069 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-plain-object": "^0.2.2", "@stdlib/assert-is-positive-integer": "^0.2.2", "@stdlib/constants-float64-pinf": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", "debug": "^2.6.9", From b6dbbef832b4e7993877537ffec61f7c1acfb41d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 3 Feb 2025 01:03:16 +0000 Subject: [PATCH 143/147] Remove files --- index.d.ts | 410 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5257 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index f6cba5d..0000000 --- a/index.d.ts +++ /dev/null @@ -1,410 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Execution context. - */ - thisArg?: ThisParameterType>; - - /** - * The maximum number of pending invocations at any one time. - */ - limit?: number; - - /** - * Boolean indicating whether to sequentially invoke the reducer function for each `collection` element. If `true`, the function sets `options.limit=1`. Default: true. - */ - series?: boolean; -} - -/** -* Callback function. -*/ -type Nullary = () => void; - -/** -* Callback function. -* -* @param error - encountered error or null -*/ -type Unary = ( error: Error | null ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Binary = ( error: Error | null, accumulator: U ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param next - a callback to be invoked after processing a collection `value` -*/ -type TernaryReducer = ( this: V, accumulator: U, value: T, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuaternaryReducer = ( this: V, accumulator: U, value: T, index: number, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuinaryReducer = ( this: V, accumulator: U, value: T, index: number, collection: Collection, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type Reducer = TernaryReducer | QuaternaryReducer | QuinaryReducer; - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result. -* -* @param collection - input collection -* @param initial - initial value -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( collection: Collection, initial: U, done: Callback ) => void; - -/** -* Interface for `reduceRightAsync`. -*/ -interface ReduceRightAsync { - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, {}, read, done ); - */ - ( collection: Collection, initial: U, options: Options, reducer: Reducer, done: Callback ): void; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, read, done ); - */ - ( collection: Collection, initial: U, reducer: Reducer, done: Callback ): void; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @throws must provide valid options - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var opts = { - * 'series': false - * }; - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( opts, read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( options: Options, reducer: Reducer ): FactoryFunction; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param reducer - function to invoke for each element in a collection - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( reducer: Reducer ): FactoryFunction; -} - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param collection - input collection -* @param initial - initial value -* @param options - function options -* @param options.thisArg - execution context -* @param options.limit - maximum number of pending invocations at any one time -* @param 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 (default: true) -* @param reducer - function to invoke for each element in a collection -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -declare var reduceRightAsync: ReduceRightAsync; - - -// EXPORTS // - -export = reduceRightAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 234a485..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as c}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";function m(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var d=m(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function f(e,m){var f,u,p;if(f={},arguments.length>1){if(u=function(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("1RZ2o","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!c(e.limit))?new TypeError(r("1RZ3P","limit",e.limit)):null):new TypeError(r("1RZ2V",t))}(f,e),u)throw u;p=m}else p=e;if(!t(p))throw new TypeError(r("1RZ3q",p));return void 0===f.series&&void 0===f.limit&&(f.series=!0),f.series?f.limit=1:f.limit||(f.limit=s),function(e,s,n){if(!i(e))throw new TypeError(r("1RZAh",e));if(!t(n))throw new TypeError(r("1RZ3q",n));return function(e,t,i,r,s){var n,o,l,c,m,f;if(c=e.length,d("Collection length: %d",c),0===c)return d("Finished processing a collection."),s(null,t);for(l=c0&&u();function u(){function s(e,i){if(!o){if(e)return o=!0,p(e);d("Accumulator: %s",JSON.stringify(i)),t=i,p()}}d("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function p(e){return e?(d("Encountered an error: %s",e.message),s(e)):(d("Processed %d of %d collection elements.",n+=1,c),m>0?u():n===c?(d("Finished processing a collection."),s(null,t)):void 0)}}(e,s,f,p,(function(e,t){if(e)return n(e);n(null,t)}))}}function u(e,t,i,r,s){if(arguments.length<5)return f(i)(e,t,r);f(i,r)(e,t,s)}e(u,"factory",f);export{u as default,f as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index e11f2cb..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/limit.js","../lib/factory.js","../lib/validate.js","../lib/main.js","../lib/index.js"],"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 logger = require( 'debug' );\n\n\n// VARIABLES //\n\nvar debug = logger( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RZ3q', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '1RZAh', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RZ3q', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '1RZ2V', 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( '1RZ2o', '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( '1RZ3P', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["debug","logger","factory","options","fcn","opts","err","f","arguments","length","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","validate","isFunction","PINF","collection","initial","done","isCollection","acc","count","flg","lim","len","idx","i","next","cb","error","result","clbk","JSON","stringify","call","message","reduceRightAsync","setReadOnly","main"],"mappings":";;81CA2BIA,uDAAQC,CAAQ,4BCoEpB,SAASC,EAASC,EAASC,GAC1B,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAA,EACFG,UAAUC,OAAS,EAAI,CAE3B,GADAH,EChDF,SAAmBD,EAAMF,GACxB,OAAMO,EAAUP,IAGXQ,EAAYR,EAAS,aACzBE,EAAKO,QAAUT,EAAQS,SAEnBD,EAAYR,EAAS,YACzBE,EAAKQ,OAASV,EAAQU,QAChBC,EAAWT,EAAKQ,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUX,EAAKQ,SAGnDF,EAAYR,EAAS,WACzBE,EAAKY,MAAQd,EAAQc,OACfC,EAAmBb,EAAKY,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASX,EAAKY,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASb,GAkBzC,CD4BQgB,CAAUd,EAAMF,GACjBG,EACJ,MAAMA,EAEPC,EAAIH,CACN,MACEG,EAAIJ,EAEL,IAAMiB,EAAYb,GACjB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAUvC,YARqB,IAAhBF,EAAKQ,aAAoC,IAAfR,EAAKY,QACnCZ,EAAKQ,QAAS,GAEVR,EAAKQ,OACTR,EAAKY,MAAQ,EACDZ,EAAKY,QACjBZ,EAAKY,MAAQI,GAed,SAA2BC,EAAYC,EAASC,GAC/C,IAAMC,EAAcH,GACnB,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,IAAMF,EAAYI,GACjB,MAAM,IAAIT,UAAWC,EAAQ,QAASQ,IAEvC,ODhGF,SAAgBF,EAAYI,EAAKrB,EAAMD,EAAKoB,GAC3C,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMR,EAAWb,OACjBT,EAAO,wBAAyB8B,GAEnB,IAARA,EAEJ,OADA9B,EAAO,qCACAwB,EAAM,KAAME,GAYpB,IATCG,EADIC,EAAMzB,EAAKY,MACTa,EAEAzB,EAAKY,MAEZjB,EAAO,wBAAyB6B,GAChC7B,EAAO,0BAA2BI,EAAIK,QAEtCkB,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVE,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKR,EAAL,CAIA,GAAKO,EAEJ,OADAP,GAAM,EACCS,EAAMF,GAEdnC,EAAO,kBAAmBsC,KAAKC,UAAWH,IAC1CV,EAAMU,EACNC,GAPC,CAQD,CA5BDrC,EAAO,6BADP+B,GAAO,EACmCO,KAAKC,UAAWjB,EAAYS,KAClD,IAAf3B,EAAIK,OACRL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOG,GACtB,IAAf9B,EAAIK,OACfL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKG,GAErD9B,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKT,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJnC,EAAO,2BAA4BmC,EAAMM,SAClCjB,EAAMW,KAGdnC,EAAO,0CADP2B,GAAS,EACgDG,GACpDC,EAAM,EACHE,IAEHN,IAAUG,GACd9B,EAAO,qCACAwB,EAAM,KAAME,SAFpB,EAIA,CACF,CCKST,CAAOK,EAAYC,EAASlB,EAAME,GAUzC,SAAe4B,EAAOT,GACrB,GAAKS,EACJ,OAAOX,EAAMW,GAEdX,EAAM,KAAME,EACZ,GACD,CACF,CE1EA,SAASgB,EAAkBpB,EAAYC,EAASpB,EAASC,EAAKoB,GAC7D,GAAKhB,UAAUC,OAAS,EACvB,OAAOP,EAASC,EAATD,CAAoBoB,EAAYC,EAASnB,GAEjDF,EAASC,EAASC,EAAlBF,CAAyBoB,EAAYC,EAASC,EAC/C,CClBAmB,EAAAC,EAAA,UAAA1C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 69bcdc8..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From d6764d1439b0d62d3029f010a505584973c20527 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 3 Feb 2025 01:03:37 +0000 Subject: [PATCH 144/147] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 245 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.factory.js | 73 - benchmark/benchmark.js | 160 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 224 - docs/types/test.ts | 166 - examples/index.js | 55 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 164 - lib/index.js | 77 - lib/limit.js | 142 - lib/main.js | 95 - lib/validate.js | 80 - package.json | 65 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 1095 ---- test/test.js | 38 - test/test.main.js | 1035 ---- test/test.validate.js | 181 - 51 files changed, 4873 insertions(+), 7315 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/limit.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 467193d..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-02-03T00:40:46.977Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1e08946..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 5358060..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index fa37f2d..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '37 1 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -460,7 +457,7 @@ reduceRightAsync( files, acc, read, done ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -531,11 +528,11 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right +[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right/tree/esm -[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce +[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index b155fd2..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var reduceRightAsync; - var arr; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - reduceRightAsync = factory( onItem ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - var acc; - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index af5c346..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var reduceRightAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=false', function benchmark( b ) { - var opts; - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'series': false - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var arr; - var len; - var acc; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'limit': 3 - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b8adcd2..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right" -%% click B href "https://github.com/stdlib-js/utils-async-reduce-right/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-reduce-right/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-reduce-right/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-reduce-right/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right -[production-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-async-reduce-right/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-async-reduce-right/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-async-reduce-right/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 47a072e..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import reduceRightAsync from '../docs/types/index'; -export = reduceRightAsync; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 530ca4d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var c=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var x=c(function(U,O){ -var R=require('@stdlib/assert-is-plain-object/dist'),h=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,k=require('@stdlib/assert-is-positive-integer/dist').isPrimitive,d=require('@stdlib/error-tools-fmtprodmsg/dist');function I(e,r){return R(r)?(h(r,"thisArg")&&(e.thisArg=r.thisArg),h(r,"series")&&(e.series=r.series,!j(e.series))?new TypeError(d('1RZ2o',"series",e.series)):h(r,"limit")&&(e.limit=r.limit,!k(e.limit))?new TypeError(d('1RZ3P',"limit",e.limit)):null):new TypeError(d('1RZ2V',r));}O.exports=I -});var P=c(function(W,E){ -var J=require("debug"),a=J("reduce-right-async:limit");function L(e,r,i,t,s){var f,m,v,n,u,g;if(n=e.length,a("Collection length: %d",n),n===0)return a("Finished processing a collection."),s(null,r);for(n0&&o();function o(){u-=1,a("Collection element %d: %s.",u,JSON.stringify(e[u])),t.length===3?t.call(i.thisArg,r,e[u],l):t.length===4?t.call(i.thisArg,r,e[u],u,l):t.call(i.thisArg,r,e[u],u,e,l);function l(w,A){if(!m){if(w)return m=!0,b(w);a("Accumulator: %s",JSON.stringify(A)),r=A,b()}}}function b(l){if(l)return a("Encountered an error: %s",l.message),s(l);if(f+=1,a("Processed %d of %d collection elements.",f,n),u>0)return o();if(f===n)return a("Finished processing a collection."),s(null,r)}}E.exports=L -});var q=c(function(X,F){ -var T=require('@stdlib/assert-is-function/dist'),S=require('@stdlib/assert-is-collection/dist'),y=require('@stdlib/error-tools-fmtprodmsg/dist'),B=require('@stdlib/constants-float64-pinf/dist'),z=x(),D=P();function G(e,r){var i,t,s;if(i={},arguments.length>1){if(t=z(i,e),t)throw t;s=r}else s=e;if(!T(s))throw new TypeError(y('1RZ3q',s));return i.series===void 0&&i.limit===void 0&&(i.series=!0),i.series?i.limit=1:i.limit||(i.limit=B),f;function f(m,v,n){if(!S(m))throw new TypeError(y('1RZAh',m));if(!T(n))throw new TypeError(y('1RZ3q',n));return D(m,v,i,s,u);function u(g,o){if(g)return n(g);n(null,o)}}}F.exports=G -});var N=c(function(Y,C){ -var p=q();function H(e,r,i,t,s){if(arguments.length<5)return p(i)(e,r,t);p(i,t)(e,r,s)}C.exports=H -});var K=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),V=N(),M=q();K(V,"factory",M);module.exports=V; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index acb9d67..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/limit.js", "../lib/factory.js", "../lib/main.js", "../lib/index.js"], - "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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\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 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 to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\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 === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, 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 ( !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, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\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* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nmodule.exports = reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' );\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, 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"], - "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,0BAA2B,EAkB/C,SAASE,EAAOC,EAAYC,EAAKC,EAAMC,EAAKC,EAAO,CAClD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMR,EAAW,OACjBF,EAAO,wBAAyBU,CAAI,EAE/BA,IAAQ,EACZ,OAAAV,EAAO,mCAAoC,EACpCM,EAAM,KAAMH,CAAI,EAYxB,IAVKO,EAAMN,EAAK,MACfK,EAAMC,EAEND,EAAML,EAAK,MAEZJ,EAAO,wBAAyBS,CAAI,EACpCT,EAAO,0BAA2BK,EAAI,MAAO,EAE7CE,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVE,EAAK,EAQP,SAASA,GAAO,CACfF,GAAO,EACPX,EAAO,6BAA8BW,EAAK,KAAK,UAAWT,EAAYS,CAAI,CAAE,CAAE,EACzEN,EAAI,SAAW,EACnBA,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGG,CAAG,EACxCT,EAAI,SAAW,EAC1BA,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGA,EAAKG,CAAG,EAExDT,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGA,EAAKT,EAAYY,CAAG,EAUrE,SAASA,EAAIC,EAAOC,EAAS,CAC5B,GAAK,CAAAR,EAIL,IAAKO,EACJ,OAAAP,EAAM,GACCS,EAAMF,CAAM,EAEpBf,EAAO,kBAAmB,KAAK,UAAWgB,CAAO,CAAE,EACnDb,EAAMa,EACNC,EAAK,EACN,CACD,CASA,SAASA,EAAMF,EAAQ,CACtB,GAAKA,EACJ,OAAAf,EAAO,2BAA4Be,EAAM,OAAQ,EAC1CT,EAAMS,CAAM,EAIpB,GAFAR,GAAS,EACTP,EAAO,0CAA2CO,EAAOG,CAAI,EACxDC,EAAM,EACV,OAAOE,EAAK,EAEb,GAAKN,IAAUG,EACd,OAAAV,EAAO,mCAAoC,EACpCM,EAAM,KAAMH,CAAI,CAEzB,CACD,CAKAL,EAAO,QAAUG,IC7IjB,IAAAiB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,gCAAiC,EACjDC,EAAW,IACXC,EAAQ,IAoEZ,SAASC,EAASC,EAASC,EAAM,CAChC,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,CAACP,EAAYW,CAAE,EACnB,MAAM,IAAI,UAAWT,EAAQ,mEAAoES,CAAE,CAAE,EAEtG,OAAKF,EAAK,SAAW,QAAUA,EAAK,QAAU,SAC7CA,EAAK,OAAS,IAEVA,EAAK,OACTA,EAAK,MAAQ,EACDA,EAAK,QACjBA,EAAK,MAAQN,GAEPS,EAaP,SAASA,EAAkBC,EAAYC,EAASC,EAAO,CACtD,GAAK,CAACd,EAAcY,CAAW,EAC9B,MAAM,IAAI,UAAWX,EAAQ,sEAAuEW,CAAW,CAAE,EAElH,GAAK,CAACb,EAAYe,CAAK,EACtB,MAAM,IAAI,UAAWb,EAAQ,mEAAoEa,CAAK,CAAE,EAEzG,OAAOV,EAAOQ,EAAYC,EAASL,EAAME,EAAGK,CAAK,EAUjD,SAASA,EAAMC,EAAOC,EAAM,CAC3B,GAAKD,EACJ,OAAOF,EAAME,CAAM,EAEpBF,EAAM,KAAMG,CAAI,CACjB,CACD,CACD,CAKAnB,EAAO,QAAUO,ICnKjB,IAAAa,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,IA8Dd,SAASC,EAAkBC,EAAYC,EAASC,EAASC,EAAKC,EAAO,CACpE,GAAK,UAAU,OAAS,EACvB,OAAON,EAASI,CAAQ,EAAGF,EAAYC,EAASE,CAAI,EAErDL,EAASI,EAASC,CAAI,EAAGH,EAAYC,EAASG,CAAK,CACpD,CAKAP,EAAO,QAAUE,IC9BjB,IAAIM,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "isPositiveInteger", "format", "validate", "opts", "options", "require_limit", "__commonJSMin", "exports", "module", "logger", "debug", "limit", "collection", "acc", "opts", "fcn", "done", "count", "flg", "lim", "len", "idx", "i", "next", "cb", "error", "result", "clbk", "require_factory", "__commonJSMin", "exports", "module", "isFunction", "isCollection", "format", "PINF", "validate", "limit", "factory", "options", "fcn", "opts", "err", "f", "reduceRightAsync", "collection", "initial", "done", "clbk", "error", "acc", "require_main", "__commonJSMin", "exports", "module", "factory", "reduceRightAsync", "collection", "initial", "options", "fcn", "done", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 078b453..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,224 +0,0 @@ - -{{alias}}( collection, initial, [options,] reducer, done ) - Applies a function against an accumulator and each element in a collection - and returns the accumulated result, iterating from right to left. - - When invoked, `reducer` is provided a maximum of five arguments: - - - accumulator: accumulated value. - - value: collection value. - - index: collection index. - - collection: the input collection. - - next: a callback to be invoked after processing a collection `value`. - - The actual number of provided arguments depends on function length. If - `reducer` accepts three arguments, `reducer` is provided: - - - accumulator - - value - - next - - If `reducer` accepts four arguments, `reducer` is provided: - - - accumulator - - value - - index - - next - - For every other `reducer` signature, `reducer` is provided all five - arguments. - - The `next` callback accepts two arguments: - - - error: error argument. - - accumulator: accumulated value. - - If a provided function calls the `next` callback with a truthy `error` - argument, the function suspends execution and immediately calls the `done` - callback for subsequent `error` handling. - - Execution is *not* guaranteed to be asynchronous. To guarantee asynchrony, - 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`). - - The function does not support dynamic collection resizing. - - If provided an empty collection, the function invokes the `done` callback - with the `initial` value as the second argument. - - The function does not skip `undefined` elements. - - When processing collection elements concurrently, *beware* of race - conditions when updating an accumulator. This is especially true when an - accumulator is a primitive (e.g., a number). In general, prefer object - accumulators. - - Parameters - ---------- - collection: Array|TypedArray|Object - Input collection over which to iterate. If provided an object, the - object must be array-like (excluding strings and functions). - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - reducer: Function - The function to invoke for each element in a collection. - - done: Function - A callback invoked either upon processing all collection elements or - upon encountering an error. - - Examples - -------- - // Basic usage: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, fcn, done ) - 3000 - 2500 - 1000 - 6500 - - // Limit number of concurrent invocations: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'limit': 2 }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 2500 - 3000 - 1000 - 6500 - - // Process concurrently: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'series': false }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 1000 - 2500 - 3000 - 6500 - - -{{alias}}.factory( [options,] fcn ) - Returns a function which applies a function against an accumulator and each - element in a collection and returns the accumulated result, iterating from - right to left. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - fcn: Function - The function to invoke for each element in a collection. - - Returns - ------- - out: Function - A function which invokes a function for each element in a collection. - - Examples - -------- - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > var opts = { 'series': false }; - > var f = {{alias}}.factory( opts, fcn ); - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > f( arr, acc, done ) - 1000 - 2500 - 3000 - 6500 - > acc = { 'sum': 0 }; - > arr = [ 1000, 1500, 2000 ]; - > f( arr, acc, done ) - 1000 - 1500 - 2000 - 4500 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0455864..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,166 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unsafe-assignment */ - -import reduceRightAsync = require( './index' ); - -const reducer = ( acc: any, value: number, index: number, next: Function ) => { - acc.sum += value; - if ( index === void 0 ) { - throw new Error( '`index` is missing.' ); - } - next( null, acc ); -}; - -const done = ( error: Error | null, acc: any ) => { - if ( error ) { - throw error; - } - if ( acc === void 0 ) { - throw new Error( '`acc` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( 2, acc, reducer, done ); // $ExpectError - reduceRightAsync( false, acc, reducer, done ); // $ExpectError - reduceRightAsync( true, acc, reducer, done ); // $ExpectError - reduceRightAsync( {}, acc, reducer, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a predicate argument which is not a predicate function... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 2, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, false, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, true, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 'abc', done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, [], done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a done callback argument which is not a function having a supported signature... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 2 ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, false ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, true ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 'abc' ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, {} ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, [] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const acc = { 'sum': 0 }; - reduceRightAsync(); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, reducer, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - reduceRightAsync.factory( reducer ); // $ExpectType FactoryFunction - reduceRightAsync.factory( { 'series': true }, reducer ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - reduceRightAsync.factory( [], reducer ); // $ExpectError - reduceRightAsync.factory( 123, reducer ); // $ExpectError - reduceRightAsync.factory( 'abc', reducer ); // $ExpectError - reduceRightAsync.factory( false, reducer ); // $ExpectError - reduceRightAsync.factory( true, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not a predicate function... -{ - reduceRightAsync.factory( {} ); // $ExpectError - reduceRightAsync.factory( true ); // $ExpectError - reduceRightAsync.factory( false ); // $ExpectError - reduceRightAsync.factory( {}, 123 ); // $ExpectError - reduceRightAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1( 12, acc, done ); // $ExpectError - fcn1( true, acc, done ); // $ExpectError - fcn1( false, acc, done ); // $ExpectError - fcn1( {}, acc, done ); // $ExpectError - - fcn1( [ 3000, 2500, 1000 ], acc, 12 ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, true ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, false ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, '5' ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, {} ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, [] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1(); // $ExpectError - fcn1( [ 3000, 2500, 1000 ] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - reduceRightAsync.factory( { 'limit': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': true }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': false }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - reduceRightAsync.factory( { 'series': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': 12 }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - reduceRightAsync.factory(); // $ExpectError - reduceRightAsync.factory( {}, reducer, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index dd64345..0000000 --- a/examples/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var resolve = require( 'path' ).resolve; -var readFile = require( '@stdlib/fs-read-file' ); -var reduceRightAsync = require( './../lib' ); - -var files = [ - resolve( __dirname, '..', 'package.json' ), - resolve( __dirname, '..', 'README.md' ) -]; - -function done( error, acc ) { - if ( error ) { - throw error; - } - console.log( acc.count ); -} - -function read( acc, file, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( file, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( null, acc ); - } - acc.count += 1; - next( null, acc ); - } -} - -var acc = { - 'count': 0 -}; -reduceRightAsync( files, acc, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 28e0a36..f6cba5d 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..97d9f26 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as c}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";function m(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var d=m(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function f(e,m){var f,u,p;if(f={},arguments.length>1){if(u=function(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("1RZ2o","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!c(e.limit))?new TypeError(r("1RZ3P","limit",e.limit)):null):new TypeError(r("1RZ2V",t))}(f,e),u)throw u;p=m}else p=e;if(!t(p))throw new TypeError(r("1RZ3q",p));return void 0===f.series&&void 0===f.limit&&(f.series=!0),f.series?f.limit=1:f.limit||(f.limit=s),function(e,s,n){if(!i(e))throw new TypeError(r("1RZAh",e));if(!t(n))throw new TypeError(r("1RZ3q",n));return function(e,t,i,r,s){var n,o,l,c,m,f;if(c=e.length,d("Collection length: %d",c),0===c)return d("Finished processing a collection."),s(null,t);for(l=c0&&u();function u(){function s(e,i){if(!o){if(e)return o=!0,p(e);d("Accumulator: %s",JSON.stringify(i)),t=i,p()}}d("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function p(e){return e?(d("Encountered an error: %s",e.message),s(e)):(d("Processed %d of %d collection elements.",n+=1,c),m>0?u():n===c?(d("Finished processing a collection."),s(null,t)):void 0)}}(e,s,f,p,(function(e,t){if(e)return n(e);n(null,t)}))}}function u(e,t,i,r,s){if(arguments.length<5)return f(i)(e,t,r);f(i,r)(e,t,s)}e(u,"factory",f);export{u as default,f as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..e11f2cb --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/limit.js","../lib/factory.js","../lib/validate.js","../lib/main.js","../lib/index.js"],"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 logger = require( 'debug' );\n\n\n// VARIABLES //\n\nvar debug = logger( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RZ3q', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '1RZAh', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RZ3q', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '1RZ2V', 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( '1RZ2o', '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( '1RZ3P', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["debug","logger","factory","options","fcn","opts","err","f","arguments","length","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","validate","isFunction","PINF","collection","initial","done","isCollection","acc","count","flg","lim","len","idx","i","next","cb","error","result","clbk","JSON","stringify","call","message","reduceRightAsync","setReadOnly","main"],"mappings":";;81CA2BIA,uDAAQC,CAAQ,4BCoEpB,SAASC,EAASC,EAASC,GAC1B,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAA,EACFG,UAAUC,OAAS,EAAI,CAE3B,GADAH,EChDF,SAAmBD,EAAMF,GACxB,OAAMO,EAAUP,IAGXQ,EAAYR,EAAS,aACzBE,EAAKO,QAAUT,EAAQS,SAEnBD,EAAYR,EAAS,YACzBE,EAAKQ,OAASV,EAAQU,QAChBC,EAAWT,EAAKQ,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUX,EAAKQ,SAGnDF,EAAYR,EAAS,WACzBE,EAAKY,MAAQd,EAAQc,OACfC,EAAmBb,EAAKY,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASX,EAAKY,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASb,GAkBzC,CD4BQgB,CAAUd,EAAMF,GACjBG,EACJ,MAAMA,EAEPC,EAAIH,CACN,MACEG,EAAIJ,EAEL,IAAMiB,EAAYb,GACjB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAUvC,YARqB,IAAhBF,EAAKQ,aAAoC,IAAfR,EAAKY,QACnCZ,EAAKQ,QAAS,GAEVR,EAAKQ,OACTR,EAAKY,MAAQ,EACDZ,EAAKY,QACjBZ,EAAKY,MAAQI,GAed,SAA2BC,EAAYC,EAASC,GAC/C,IAAMC,EAAcH,GACnB,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,IAAMF,EAAYI,GACjB,MAAM,IAAIT,UAAWC,EAAQ,QAASQ,IAEvC,ODhGF,SAAgBF,EAAYI,EAAKrB,EAAMD,EAAKoB,GAC3C,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMR,EAAWb,OACjBT,EAAO,wBAAyB8B,GAEnB,IAARA,EAEJ,OADA9B,EAAO,qCACAwB,EAAM,KAAME,GAYpB,IATCG,EADIC,EAAMzB,EAAKY,MACTa,EAEAzB,EAAKY,MAEZjB,EAAO,wBAAyB6B,GAChC7B,EAAO,0BAA2BI,EAAIK,QAEtCkB,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVE,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKR,EAAL,CAIA,GAAKO,EAEJ,OADAP,GAAM,EACCS,EAAMF,GAEdnC,EAAO,kBAAmBsC,KAAKC,UAAWH,IAC1CV,EAAMU,EACNC,GAPC,CAQD,CA5BDrC,EAAO,6BADP+B,GAAO,EACmCO,KAAKC,UAAWjB,EAAYS,KAClD,IAAf3B,EAAIK,OACRL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOG,GACtB,IAAf9B,EAAIK,OACfL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKG,GAErD9B,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKT,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJnC,EAAO,2BAA4BmC,EAAMM,SAClCjB,EAAMW,KAGdnC,EAAO,0CADP2B,GAAS,EACgDG,GACpDC,EAAM,EACHE,IAEHN,IAAUG,GACd9B,EAAO,qCACAwB,EAAM,KAAME,SAFpB,EAIA,CACF,CCKST,CAAOK,EAAYC,EAASlB,EAAME,GAUzC,SAAe4B,EAAOT,GACrB,GAAKS,EACJ,OAAOX,EAAMW,GAEdX,EAAM,KAAME,EACZ,GACD,CACF,CE1EA,SAASgB,EAAkBpB,EAAYC,EAASpB,EAASC,EAAKoB,GAC7D,GAAKhB,UAAUC,OAAS,EACvB,OAAOP,EAASC,EAATD,CAAoBoB,EAAYC,EAASnB,GAEjDF,EAASC,EAASC,EAAlBF,CAAyBoB,EAAYC,EAASC,EAC/C,CClBAmB,EAAAC,EAAA,UAAA1C"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index e107128..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,164 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var validate = require( './validate.js' ); -var limit = require( './limit.js' ); - - -// MAIN // - -/** -* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} last argument must be a function -* @returns {Function} function which invokes the provided function once for each element in a collection -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error, data ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var opts = { -* 'series': false -* }; -* -* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: -* var reduceRightAsync = factory( opts, read ); -* -* // Create a collection over which to iterate: -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* // Define a callback which handles errors: -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* // Run `read` for each element in `files`: -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, done ); -*/ -function factory( options, fcn ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = fcn; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '1RZ3q', f ) ); - } - if ( opts.series === void 0 && opts.limit === void 0 ) { - opts.series = true; - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return reduceRightAsync; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * @private - * @param {Collection} collection - input collection - * @param {*} initial - initial value - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be a collection - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function reduceRightAsync( collection, initial, done ) { - if ( !isCollection( collection ) ) { - throw new TypeError( format( '1RZAh', collection ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '1RZ3q', done ) ); - } - return limit( collection, initial, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {*} [acc] - accumulated value - * @returns {void} - */ - function clbk( error, acc ) { - if ( error ) { - return done( error ); - } - done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ae657ff..0000000 --- a/lib/index.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* @module @stdlib/utils-async-reduce-right -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' ); -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/limit.js b/lib/limit.js deleted file mode 100644 index cdb60af..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); - - -// VARIABLES // - -var debug = logger( 'reduce-right-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each element in a collection, limiting the number of concurrently pending functions and iterating from right to left. -* -* @private -* @param {Collection} collection - input collection -* @param {*} acc - initial value -* @param {Options} opts - function options -* @param {*} [opts.thisArg] - execution context -* @param {PositiveInteger} [opts.limit] - maximum number of pending function invocations -* @param {Function} fcn - function to invoke -* @param {Callback} done - function to invoke upon completion or upon encountering an error -* @returns {void} -*/ -function limit( collection, acc, opts, fcn, done ) { - var count; - var flg; - var lim; - var len; - var idx; - var i; - - len = collection.length; - debug( 'Collection length: %d', len ); - - if ( len === 0 ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - count = 0; - idx = len; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all collection elements... - if ( idx > 0 ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next element in a collection. - * - * @private - */ - function next() { - idx -= 1; - debug( 'Collection element %d: %s.', idx, JSON.stringify( collection[ idx ] ) ); - if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], cb ); - } else if ( fcn.length === 4 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, cb ); - } else { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len - } - /** - * Callback invoked once a provided function finishes processing a collection element. - * - * @private - * @param {*} [error] - error - * @param {*} [result] - accumulation result - * @returns {void} - */ - function cb( error, result ) { - if ( flg ) { - // Prevent further processing of collection elements: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Accumulator: %s', JSON.stringify( result ) ); - acc = result; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next collection element. - * - * @private - * @param {*} [error] - error - * @returns {void} - */ - function clbk( error ) { - if ( error ) { - debug( 'Encountered an error: %s', error.message ); - return done( error ); - } - count += 1; - debug( 'Processed %d of %d collection elements.', count, len ); - if ( idx > 0 ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index c8b0d0f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param {Collection} collection - input collection -* @param {*} initial - initial value -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} second-to-last argument must be a function -* @throws {TypeError} last argument must be a function -* @returns {void} -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -function reduceRightAsync( collection, initial, options, fcn, done ) { - if ( arguments.length < 5 ) { - return factory( options )( collection, initial, fcn ); - } - factory( options, fcn )( collection, initial, done ); -} - - -// EXPORTS // - -module.exports = reduceRightAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 0c666fe..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @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 -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'thisArg': {}, -* 'series': false, -* 'limit': 10 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '1RZ2V', options ) ); - } - if ( hasOwnProp( options, 'thisArg' ) ) { - opts.thisArg = options.thisArg; - } - if ( hasOwnProp( options, 'series' ) ) { - opts.series = options.series; - if ( !isBoolean( opts.series ) ) { - return new TypeError( format( '1RZ2o', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '1RZ3P', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index fa2e069..563c57c 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,44 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-collection": "^0.2.2", - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/assert-is-positive-integer": "^0.2.2", - "@stdlib/constants-float64-pinf": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "debug": "^2.6.9", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/constants-float64-eps": "^0.2.2", - "@stdlib/fs-read-file": "^0.2.2", - "@stdlib/utils-noop": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..69bcdc8 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 8244931..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1095 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( {}, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, next ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - factory( opts, next ); - }; - } -}); - -tape( 'the function returns a function (no options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided a collection (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a collection (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (1 argument)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (2 arguments)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with five arguments', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn() { - var value; - var next; - var acc; - var k; - - acc = arguments[ 0 ]; - value = arguments[ 1 ]; - k = arguments[ 2 ]; - next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( k, i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the returned function supports processing collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements concurrently', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 100, 250, 300 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements sequentially (limit = 1)', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of collection elements which are processed at any one time', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 250, 300, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 250, 100, 300 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var reduceRightAsync; - var arr; - - reduceRightAsync = factory( fcn ); - arr = []; - - reduceRightAsync( arr, 0, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var reduceRightAsync; - var obj; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = []; - obj = {}; - reduceRightAsync( arr, obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - i = 0; - - reduceRightAsync( arr, {}, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, acc ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the returned function does not skip empty elements', function test( t ) { - var reduceRightAsync; - var expected; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index f273a40..0000000 --- a/test/test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof reduceRightAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 1893240..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1035 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a collection', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (no options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, next, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, 0 ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - reduceRightAsync( [ 1, 2, 3 ], 0, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (1 argument)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (2 arguments)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with five arguments', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn() { - var next; - var acc; - var v; - - next = arguments[ 4 ]; - acc = arguments[ 0 ]; - v = arguments[ 1 ]; - - i -= 1; - j += 1; - - t.strictEqual( v, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, v ); - - function onTimeout() { - acc.sum += v; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'by default, the function processes collection elements sequentially', function test( t ) { - var values; - var count; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements concurrently', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 100, 250, 300 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': true - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially (limit = 1)', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var arr; - var ctx; - - arr = [ 3, 2, 1 ]; - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 3, 2, 1 ]; - opts = { - 'series': true - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 250, 100, 300 ]; - opts = { - 'limit': 2 - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var arr = []; - reduceRightAsync( arr, 0, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var arr = []; - var obj = {}; - - reduceRightAsync( arr, obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - arr = [ 3, 2, 1 ]; - i = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, value ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the function does not skip empty elements', function test( t ) { - var expected; - var arr; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, fcn, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 7660838..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,181 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `limit` option which is not a positive integer', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - -5, - 0, - 3.14, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'limit': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `series` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'series': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function accepts any value for the `thisArg` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'thisArg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err, null, 'returns null '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'thisArg': {}, - 'series': false, - 'limit': 10 - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From 665b0cafcf25397c42ed99ecfaaba8bc6cc9a81d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 12 May 2025 00:30:30 +0000 Subject: [PATCH 145/147] Transform error messages --- lib/factory.js | 8 ++++---- lib/validate.js | 8 ++++---- package.json | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 1125052..e107128 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -22,7 +22,7 @@ var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var PINF = require( '@stdlib/constants-float64-pinf' ); var validate = require( './validate.js' ); var limit = require( './limit.js' ); @@ -109,7 +109,7 @@ function factory( options, fcn ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '1RZ3q', f ) ); } if ( opts.series === void 0 && opts.limit === void 0 ) { opts.series = true; @@ -134,10 +134,10 @@ function factory( options, fcn ) { */ function reduceRightAsync( collection, initial, done ) { if ( !isCollection( collection ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a collection. Value: `%s`.', collection ) ); + throw new TypeError( format( '1RZAh', collection ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '1RZ3q', done ) ); } return limit( collection, initial, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index 9ba927e..0c666fe 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,7 +54,7 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '1RZ2V', options ) ); } if ( hasOwnProp( options, 'thisArg' ) ) { opts.thisArg = options.thisArg; @@ -62,13 +62,13 @@ function validate( opts, options ) { if ( hasOwnProp( options, 'series' ) ) { opts.series = options.series; if ( !isBoolean( opts.series ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'series', opts.series ) ); + return new TypeError( format( '1RZ2o', 'series', opts.series ) ); } } if ( hasOwnProp( options, 'limit' ) ) { opts.limit = options.limit; if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'limit', opts.limit ) ); + return new TypeError( format( '1RZ3P', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index 48d1408..fa2e069 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-plain-object": "^0.2.2", "@stdlib/assert-is-positive-integer": "^0.2.2", "@stdlib/constants-float64-pinf": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", "debug": "^2.6.9", From 7bae151a7bfa0b2f9fca348bd74d6bbc88cd6f95 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 12 May 2025 00:31:04 +0000 Subject: [PATCH 146/147] Remove files --- index.d.ts | 410 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5257 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index f6cba5d..0000000 --- a/index.d.ts +++ /dev/null @@ -1,410 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Execution context. - */ - thisArg?: ThisParameterType>; - - /** - * The maximum number of pending invocations at any one time. - */ - limit?: number; - - /** - * Boolean indicating whether to sequentially invoke the reducer function for each `collection` element. If `true`, the function sets `options.limit=1`. Default: true. - */ - series?: boolean; -} - -/** -* Callback function. -*/ -type Nullary = () => void; - -/** -* Callback function. -* -* @param error - encountered error or null -*/ -type Unary = ( error: Error | null ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Binary = ( error: Error | null, accumulator: U ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param accumulator - accumulated value -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param next - a callback to be invoked after processing a collection `value` -*/ -type TernaryReducer = ( this: V, accumulator: U, value: T, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuaternaryReducer = ( this: V, accumulator: U, value: T, index: number, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type QuinaryReducer = ( this: V, accumulator: U, value: T, index: number, collection: Collection, next: Callback ) => void; - -/** -* Reducer function invoked for each element in a collection. -* -* @param accumulator - accumulated value -* @param value - collection value -* @param index - collection index -* @param collection - the input collection -* @param next - a callback to be invoked after processing a collection `value` -*/ -type Reducer = TernaryReducer | QuaternaryReducer | QuinaryReducer; - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result. -* -* @param collection - input collection -* @param initial - initial value -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( collection: Collection, initial: U, done: Callback ) => void; - -/** -* Interface for `reduceRightAsync`. -*/ -interface ReduceRightAsync { - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, {}, read, done ); - */ - ( collection: Collection, initial: U, options: Options, reducer: Reducer, done: Callback ): void; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param collection - input collection - * @param initial - initial value - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, read, done ); - */ - ( collection: Collection, initial: U, reducer: Reducer, done: Callback ): void; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param options - function options - * @param options.thisArg - execution context - * @param options.limit - maximum number of pending invocations at any one time - * @param 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 (default: true) - * @param reducer - function to invoke for each element in a collection - * @throws must provide valid options - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * var opts = { - * 'series': false - * }; - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( opts, read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( options: Options, reducer: Reducer ): FactoryFunction; - - /** - * Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - 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`). - * - * @param reducer - function to invoke for each element in a collection - * @returns function which invokes the provided function once for each element in a collection - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( acc, file, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( file, opts, onFile ); - * - * function onFile( error, data ) { - * if ( error ) { - * return next( null, acc ); - * } - * acc.count += 1; - * next( null, acc ); - * } - * } - * - * // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: - * var reduceRightAsync = factory( read ); - * - * // Create a collection over which to iterate: - * var files = [ - * './beep.js', - * './boop.js' - * ]; - * - * // Define a callback which handles errors: - * function done( error, acc ) { - * if ( error ) { - * throw error; - * } - * console.log( acc.count ); - * } - * - * // Run `read` for each element in `files`: - * var acc = { - * 'count': 0 - * }; - * reduceRightAsync( files, acc, done ); - */ - factory( reducer: Reducer ): FactoryFunction; -} - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param collection - input collection -* @param initial - initial value -* @param options - function options -* @param options.thisArg - execution context -* @param options.limit - maximum number of pending invocations at any one time -* @param 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 (default: true) -* @param reducer - function to invoke for each element in a collection -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -declare var reduceRightAsync: ReduceRightAsync; - - -// EXPORTS // - -export = reduceRightAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 97d9f26..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as c}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";function m(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var d=m(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function f(e,m){var f,u,p;if(f={},arguments.length>1){if(u=function(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("1RZ2o","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!c(e.limit))?new TypeError(r("1RZ3P","limit",e.limit)):null):new TypeError(r("1RZ2V",t))}(f,e),u)throw u;p=m}else p=e;if(!t(p))throw new TypeError(r("1RZ3q",p));return void 0===f.series&&void 0===f.limit&&(f.series=!0),f.series?f.limit=1:f.limit||(f.limit=s),function(e,s,n){if(!i(e))throw new TypeError(r("1RZAh",e));if(!t(n))throw new TypeError(r("1RZ3q",n));return function(e,t,i,r,s){var n,o,l,c,m,f;if(c=e.length,d("Collection length: %d",c),0===c)return d("Finished processing a collection."),s(null,t);for(l=c0&&u();function u(){function s(e,i){if(!o){if(e)return o=!0,p(e);d("Accumulator: %s",JSON.stringify(i)),t=i,p()}}d("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function p(e){return e?(d("Encountered an error: %s",e.message),s(e)):(d("Processed %d of %d collection elements.",n+=1,c),m>0?u():n===c?(d("Finished processing a collection."),s(null,t)):void 0)}}(e,s,f,p,(function(e,t){if(e)return n(e);n(null,t)}))}}function u(e,t,i,r,s){if(arguments.length<5)return f(i)(e,t,r);f(i,r)(e,t,s)}e(u,"factory",f);export{u as default,f as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index e11f2cb..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/limit.js","../lib/factory.js","../lib/validate.js","../lib/main.js","../lib/index.js"],"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 logger = require( 'debug' );\n\n\n// VARIABLES //\n\nvar debug = logger( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RZ3q', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '1RZAh', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RZ3q', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '1RZ2V', 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( '1RZ2o', '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( '1RZ3P', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["debug","logger","factory","options","fcn","opts","err","f","arguments","length","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","validate","isFunction","PINF","collection","initial","done","isCollection","acc","count","flg","lim","len","idx","i","next","cb","error","result","clbk","JSON","stringify","call","message","reduceRightAsync","setReadOnly","main"],"mappings":";;81CA2BIA,uDAAQC,CAAQ,4BCoEpB,SAASC,EAASC,EAASC,GAC1B,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAA,EACFG,UAAUC,OAAS,EAAI,CAE3B,GADAH,EChDF,SAAmBD,EAAMF,GACxB,OAAMO,EAAUP,IAGXQ,EAAYR,EAAS,aACzBE,EAAKO,QAAUT,EAAQS,SAEnBD,EAAYR,EAAS,YACzBE,EAAKQ,OAASV,EAAQU,QAChBC,EAAWT,EAAKQ,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUX,EAAKQ,SAGnDF,EAAYR,EAAS,WACzBE,EAAKY,MAAQd,EAAQc,OACfC,EAAmBb,EAAKY,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASX,EAAKY,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASb,GAkBzC,CD4BQgB,CAAUd,EAAMF,GACjBG,EACJ,MAAMA,EAEPC,EAAIH,CACN,MACEG,EAAIJ,EAEL,IAAMiB,EAAYb,GACjB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAUvC,YARqB,IAAhBF,EAAKQ,aAAoC,IAAfR,EAAKY,QACnCZ,EAAKQ,QAAS,GAEVR,EAAKQ,OACTR,EAAKY,MAAQ,EACDZ,EAAKY,QACjBZ,EAAKY,MAAQI,GAed,SAA2BC,EAAYC,EAASC,GAC/C,IAAMC,EAAcH,GACnB,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,IAAMF,EAAYI,GACjB,MAAM,IAAIT,UAAWC,EAAQ,QAASQ,IAEvC,ODhGF,SAAgBF,EAAYI,EAAKrB,EAAMD,EAAKoB,GAC3C,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMR,EAAWb,OACjBT,EAAO,wBAAyB8B,GAEnB,IAARA,EAEJ,OADA9B,EAAO,qCACAwB,EAAM,KAAME,GAYpB,IATCG,EADIC,EAAMzB,EAAKY,MACTa,EAEAzB,EAAKY,MAEZjB,EAAO,wBAAyB6B,GAChC7B,EAAO,0BAA2BI,EAAIK,QAEtCkB,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVE,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKR,EAAL,CAIA,GAAKO,EAEJ,OADAP,GAAM,EACCS,EAAMF,GAEdnC,EAAO,kBAAmBsC,KAAKC,UAAWH,IAC1CV,EAAMU,EACNC,GAPC,CAQD,CA5BDrC,EAAO,6BADP+B,GAAO,EACmCO,KAAKC,UAAWjB,EAAYS,KAClD,IAAf3B,EAAIK,OACRL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOG,GACtB,IAAf9B,EAAIK,OACfL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKG,GAErD9B,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKT,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJnC,EAAO,2BAA4BmC,EAAMM,SAClCjB,EAAMW,KAGdnC,EAAO,0CADP2B,GAAS,EACgDG,GACpDC,EAAM,EACHE,IAEHN,IAAUG,GACd9B,EAAO,qCACAwB,EAAM,KAAME,SAFpB,EAIA,CACF,CCKST,CAAOK,EAAYC,EAASlB,EAAME,GAUzC,SAAe4B,EAAOT,GACrB,GAAKS,EACJ,OAAOX,EAAMW,GAEdX,EAAM,KAAME,EACZ,GACD,CACF,CE1EA,SAASgB,EAAkBpB,EAAYC,EAASpB,EAASC,EAAKoB,GAC7D,GAAKhB,UAAUC,OAAS,EACvB,OAAOP,EAASC,EAATD,CAAoBoB,EAAYC,EAASnB,GAEjDF,EAASC,EAASC,EAAlBF,CAAyBoB,EAAYC,EAASC,EAC/C,CClBAmB,EAAAC,EAAA,UAAA1C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 69bcdc8..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 00ce66cef270f0957ccef2a71326b8d40b9b9365 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 12 May 2025 00:31:26 +0000 Subject: [PATCH 147/147] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 194 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 245 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.factory.js | 73 - benchmark/benchmark.js | 160 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 224 - docs/types/test.ts | 166 - examples/index.js | 55 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 164 - lib/index.js | 77 - lib/limit.js | 142 - lib/main.js | 95 - lib/validate.js | 80 - package.json | 65 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 1095 ---- test/test.js | 38 - test/test.main.js | 1035 ---- test/test.validate.js | 181 - 51 files changed, 4873 insertions(+), 7319 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/limit.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index d361b81..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-05-12T00:30:04.476Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index f665718..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/contributing/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 5358060..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index fa37f2d..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '37 1 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -460,7 +457,7 @@ reduceRightAsync( files, acc, read, done ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -531,11 +528,11 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right +[@stdlib/utils/async/for-each-right]: https://github.com/stdlib-js/utils-async-for-each-right/tree/esm -[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce +[@stdlib/utils/async/reduce]: https://github.com/stdlib-js/utils-async-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index b155fd2..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var reduceRightAsync; - var arr; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - reduceRightAsync = factory( onItem ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - var acc; - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index af5c346..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var pkg = require( './../package.json' ).name; -var reduceRightAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=false', function benchmark( b ) { - var opts; - var arr; - var acc; - var len; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'series': false - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var arr; - var len; - var acc; - var i; - - function onItem( acc, v, i, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - acc.sum += v; - clbk( null, acc ); - } - } - opts = { - 'limit': 3 - }; - arr = new Array( 100 ); - len = arr.length; - for ( i = 0; i < len; i++ ) { - arr[ i ] = EPS; - } - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - arr[ 0 ] += 10.0; - acc = { - 'sum': 0.0 - }; - return reduceRightAsync( arr, acc, opts, onItem, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b8adcd2..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right" -%% click B href "https://github.com/stdlib-js/utils-async-reduce-right/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-reduce-right/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-reduce-right/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-reduce-right/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/reduce-right -[production-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-async-reduce-right/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-async-reduce-right/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-async-reduce-right/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-async-reduce-right/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 47a072e..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import reduceRightAsync from '../docs/types/index'; -export = reduceRightAsync; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 530ca4d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var c=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var x=c(function(U,O){ -var R=require('@stdlib/assert-is-plain-object/dist'),h=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,k=require('@stdlib/assert-is-positive-integer/dist').isPrimitive,d=require('@stdlib/error-tools-fmtprodmsg/dist');function I(e,r){return R(r)?(h(r,"thisArg")&&(e.thisArg=r.thisArg),h(r,"series")&&(e.series=r.series,!j(e.series))?new TypeError(d('1RZ2o',"series",e.series)):h(r,"limit")&&(e.limit=r.limit,!k(e.limit))?new TypeError(d('1RZ3P',"limit",e.limit)):null):new TypeError(d('1RZ2V',r));}O.exports=I -});var P=c(function(W,E){ -var J=require("debug"),a=J("reduce-right-async:limit");function L(e,r,i,t,s){var f,m,v,n,u,g;if(n=e.length,a("Collection length: %d",n),n===0)return a("Finished processing a collection."),s(null,r);for(n0&&o();function o(){u-=1,a("Collection element %d: %s.",u,JSON.stringify(e[u])),t.length===3?t.call(i.thisArg,r,e[u],l):t.length===4?t.call(i.thisArg,r,e[u],u,l):t.call(i.thisArg,r,e[u],u,e,l);function l(w,A){if(!m){if(w)return m=!0,b(w);a("Accumulator: %s",JSON.stringify(A)),r=A,b()}}}function b(l){if(l)return a("Encountered an error: %s",l.message),s(l);if(f+=1,a("Processed %d of %d collection elements.",f,n),u>0)return o();if(f===n)return a("Finished processing a collection."),s(null,r)}}E.exports=L -});var q=c(function(X,F){ -var T=require('@stdlib/assert-is-function/dist'),S=require('@stdlib/assert-is-collection/dist'),y=require('@stdlib/error-tools-fmtprodmsg/dist'),B=require('@stdlib/constants-float64-pinf/dist'),z=x(),D=P();function G(e,r){var i,t,s;if(i={},arguments.length>1){if(t=z(i,e),t)throw t;s=r}else s=e;if(!T(s))throw new TypeError(y('1RZ3q',s));return i.series===void 0&&i.limit===void 0&&(i.series=!0),i.series?i.limit=1:i.limit||(i.limit=B),f;function f(m,v,n){if(!S(m))throw new TypeError(y('1RZAh',m));if(!T(n))throw new TypeError(y('1RZ3q',n));return D(m,v,i,s,u);function u(g,o){if(g)return n(g);n(null,o)}}}F.exports=G -});var N=c(function(Y,C){ -var p=q();function H(e,r,i,t,s){if(arguments.length<5)return p(i)(e,r,t);p(i,t)(e,r,s)}C.exports=H -});var K=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),V=N(),M=q();K(V,"factory",M);module.exports=V; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index acb9d67..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/limit.js", "../lib/factory.js", "../lib/main.js", "../lib/index.js"], - "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( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\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 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 to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\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 === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, 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 ( !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, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\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* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nmodule.exports = reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' );\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, 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"], - "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,0BAA2B,EAkB/C,SAASE,EAAOC,EAAYC,EAAKC,EAAMC,EAAKC,EAAO,CAClD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMR,EAAW,OACjBF,EAAO,wBAAyBU,CAAI,EAE/BA,IAAQ,EACZ,OAAAV,EAAO,mCAAoC,EACpCM,EAAM,KAAMH,CAAI,EAYxB,IAVKO,EAAMN,EAAK,MACfK,EAAMC,EAEND,EAAML,EAAK,MAEZJ,EAAO,wBAAyBS,CAAI,EACpCT,EAAO,0BAA2BK,EAAI,MAAO,EAE7CE,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVE,EAAK,EAQP,SAASA,GAAO,CACfF,GAAO,EACPX,EAAO,6BAA8BW,EAAK,KAAK,UAAWT,EAAYS,CAAI,CAAE,CAAE,EACzEN,EAAI,SAAW,EACnBA,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGG,CAAG,EACxCT,EAAI,SAAW,EAC1BA,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGA,EAAKG,CAAG,EAExDT,EAAI,KAAMD,EAAK,QAASD,EAAKD,EAAYS,CAAI,EAAGA,EAAKT,EAAYY,CAAG,EAUrE,SAASA,EAAIC,EAAOC,EAAS,CAC5B,GAAK,CAAAR,EAIL,IAAKO,EACJ,OAAAP,EAAM,GACCS,EAAMF,CAAM,EAEpBf,EAAO,kBAAmB,KAAK,UAAWgB,CAAO,CAAE,EACnDb,EAAMa,EACNC,EAAK,EACN,CACD,CASA,SAASA,EAAMF,EAAQ,CACtB,GAAKA,EACJ,OAAAf,EAAO,2BAA4Be,EAAM,OAAQ,EAC1CT,EAAMS,CAAM,EAIpB,GAFAR,GAAS,EACTP,EAAO,0CAA2CO,EAAOG,CAAI,EACxDC,EAAM,EACV,OAAOE,EAAK,EAEb,GAAKN,IAAUG,EACd,OAAAV,EAAO,mCAAoC,EACpCM,EAAM,KAAMH,CAAI,CAEzB,CACD,CAKAL,EAAO,QAAUG,IC7IjB,IAAAiB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,gCAAiC,EACjDC,EAAW,IACXC,EAAQ,IAoEZ,SAASC,EAASC,EAASC,EAAM,CAChC,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,CAACP,EAAYW,CAAE,EACnB,MAAM,IAAI,UAAWT,EAAQ,mEAAoES,CAAE,CAAE,EAEtG,OAAKF,EAAK,SAAW,QAAUA,EAAK,QAAU,SAC7CA,EAAK,OAAS,IAEVA,EAAK,OACTA,EAAK,MAAQ,EACDA,EAAK,QACjBA,EAAK,MAAQN,GAEPS,EAaP,SAASA,EAAkBC,EAAYC,EAASC,EAAO,CACtD,GAAK,CAACd,EAAcY,CAAW,EAC9B,MAAM,IAAI,UAAWX,EAAQ,sEAAuEW,CAAW,CAAE,EAElH,GAAK,CAACb,EAAYe,CAAK,EACtB,MAAM,IAAI,UAAWb,EAAQ,mEAAoEa,CAAK,CAAE,EAEzG,OAAOV,EAAOQ,EAAYC,EAASL,EAAME,EAAGK,CAAK,EAUjD,SAASA,EAAMC,EAAOC,EAAM,CAC3B,GAAKD,EACJ,OAAOF,EAAME,CAAM,EAEpBF,EAAM,KAAMG,CAAI,CACjB,CACD,CACD,CAKAnB,EAAO,QAAUO,ICnKjB,IAAAa,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,IA8Dd,SAASC,EAAkBC,EAAYC,EAASC,EAASC,EAAKC,EAAO,CACpE,GAAK,UAAU,OAAS,EACvB,OAAON,EAASI,CAAQ,EAAGF,EAAYC,EAASE,CAAI,EAErDL,EAASI,EAASC,CAAI,EAAGH,EAAYC,EAASG,CAAK,CACpD,CAKAP,EAAO,QAAUE,IC9BjB,IAAIM,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "isPositiveInteger", "format", "validate", "opts", "options", "require_limit", "__commonJSMin", "exports", "module", "logger", "debug", "limit", "collection", "acc", "opts", "fcn", "done", "count", "flg", "lim", "len", "idx", "i", "next", "cb", "error", "result", "clbk", "require_factory", "__commonJSMin", "exports", "module", "isFunction", "isCollection", "format", "PINF", "validate", "limit", "factory", "options", "fcn", "opts", "err", "f", "reduceRightAsync", "collection", "initial", "done", "clbk", "error", "acc", "require_main", "__commonJSMin", "exports", "module", "factory", "reduceRightAsync", "collection", "initial", "options", "fcn", "done", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 078b453..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,224 +0,0 @@ - -{{alias}}( collection, initial, [options,] reducer, done ) - Applies a function against an accumulator and each element in a collection - and returns the accumulated result, iterating from right to left. - - When invoked, `reducer` is provided a maximum of five arguments: - - - accumulator: accumulated value. - - value: collection value. - - index: collection index. - - collection: the input collection. - - next: a callback to be invoked after processing a collection `value`. - - The actual number of provided arguments depends on function length. If - `reducer` accepts three arguments, `reducer` is provided: - - - accumulator - - value - - next - - If `reducer` accepts four arguments, `reducer` is provided: - - - accumulator - - value - - index - - next - - For every other `reducer` signature, `reducer` is provided all five - arguments. - - The `next` callback accepts two arguments: - - - error: error argument. - - accumulator: accumulated value. - - If a provided function calls the `next` callback with a truthy `error` - argument, the function suspends execution and immediately calls the `done` - callback for subsequent `error` handling. - - Execution is *not* guaranteed to be asynchronous. To guarantee asynchrony, - 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`). - - The function does not support dynamic collection resizing. - - If provided an empty collection, the function invokes the `done` callback - with the `initial` value as the second argument. - - The function does not skip `undefined` elements. - - When processing collection elements concurrently, *beware* of race - conditions when updating an accumulator. This is especially true when an - accumulator is a primitive (e.g., a number). In general, prefer object - accumulators. - - Parameters - ---------- - collection: Array|TypedArray|Object - Input collection over which to iterate. If provided an object, the - object must be array-like (excluding strings and functions). - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - reducer: Function - The function to invoke for each element in a collection. - - done: Function - A callback invoked either upon processing all collection elements or - upon encountering an error. - - Examples - -------- - // Basic usage: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, fcn, done ) - 3000 - 2500 - 1000 - 6500 - - // Limit number of concurrent invocations: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'limit': 2 }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 2500 - 3000 - 1000 - 6500 - - // Process concurrently: - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var opts = { 'series': false }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > {{alias}}( arr, acc, opts, fcn, done ) - 1000 - 2500 - 3000 - 6500 - - -{{alias}}.factory( [options,] fcn ) - Returns a function which applies a function against an accumulator and each - element in a collection and returns the accumulated result, iterating from - right to left. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.limit: integer (optional) - Maximum number of pending invocations. Default: Infinity. - - options.series: boolean (optional) - Boolean indicating whether to process each collection element - sequentially. Default: true. - - options.thisArg: any (optional) - Execution context. - - fcn: Function - The function to invoke for each element in a collection. - - Returns - ------- - out: Function - A function which invokes a function for each element in a collection. - - Examples - -------- - > function fcn( acc, value, index, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... console.log( value ); - ... acc.sum += value; - ... next( null, acc ); - ... } - ... }; - > var opts = { 'series': false }; - > var f = {{alias}}.factory( opts, fcn ); - > function done( error, acc ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( acc.sum ); - ... }; - > var arr = [ 1000, 2500, 3000 ]; - > var acc = { 'sum': 0 }; - > f( arr, acc, done ) - 1000 - 2500 - 3000 - 6500 - > acc = { 'sum': 0 }; - > arr = [ 1000, 1500, 2000 ]; - > f( arr, acc, done ) - 1000 - 1500 - 2000 - 4500 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0455864..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,166 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unsafe-assignment */ - -import reduceRightAsync = require( './index' ); - -const reducer = ( acc: any, value: number, index: number, next: Function ) => { - acc.sum += value; - if ( index === void 0 ) { - throw new Error( '`index` is missing.' ); - } - next( null, acc ); -}; - -const done = ( error: Error | null, acc: any ) => { - if ( error ) { - throw error; - } - if ( acc === void 0 ) { - throw new Error( '`acc` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( 2, acc, reducer, done ); // $ExpectError - reduceRightAsync( false, acc, reducer, done ); // $ExpectError - reduceRightAsync( true, acc, reducer, done ); // $ExpectError - reduceRightAsync( {}, acc, reducer, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a predicate argument which is not a predicate function... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 2, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, false, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, true, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, 'abc', done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, done ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, [], done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a done callback argument which is not a function having a supported signature... -{ - const acc = { 'sum': 0 }; - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 2 ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, false ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, true ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, 'abc' ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, {} ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, [] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const acc = { 'sum': 0 }; - reduceRightAsync(); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ] ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, reducer ); // $ExpectError - reduceRightAsync( [ 3000, 2500, 1000 ], acc, {}, reducer, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - reduceRightAsync.factory( reducer ); // $ExpectType FactoryFunction - reduceRightAsync.factory( { 'series': true }, reducer ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - reduceRightAsync.factory( [], reducer ); // $ExpectError - reduceRightAsync.factory( 123, reducer ); // $ExpectError - reduceRightAsync.factory( 'abc', reducer ); // $ExpectError - reduceRightAsync.factory( false, reducer ); // $ExpectError - reduceRightAsync.factory( true, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not a predicate function... -{ - reduceRightAsync.factory( {} ); // $ExpectError - reduceRightAsync.factory( true ); // $ExpectError - reduceRightAsync.factory( false ); // $ExpectError - reduceRightAsync.factory( {}, 123 ); // $ExpectError - reduceRightAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1( 12, acc, done ); // $ExpectError - fcn1( true, acc, done ); // $ExpectError - fcn1( false, acc, done ); // $ExpectError - fcn1( {}, acc, done ); // $ExpectError - - fcn1( [ 3000, 2500, 1000 ], acc, 12 ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, true ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, false ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, '5' ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, {} ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, [] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const acc = { 'sum': 0 }; - const fcn1 = reduceRightAsync.factory( reducer ); - fcn1(); // $ExpectError - fcn1( [ 3000, 2500, 1000 ] ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc ); // $ExpectError - fcn1( [ 3000, 2500, 1000 ], acc, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - reduceRightAsync.factory( { 'limit': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': true }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': false }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'limit': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - reduceRightAsync.factory( { 'series': '12' }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': 12 }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': {} }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': [] }, reducer ); // $ExpectError - reduceRightAsync.factory( { 'series': ( x: number ): number => x }, reducer ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - reduceRightAsync.factory(); // $ExpectError - reduceRightAsync.factory( {}, reducer, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index dd64345..0000000 --- a/examples/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var resolve = require( 'path' ).resolve; -var readFile = require( '@stdlib/fs-read-file' ); -var reduceRightAsync = require( './../lib' ); - -var files = [ - resolve( __dirname, '..', 'package.json' ), - resolve( __dirname, '..', 'README.md' ) -]; - -function done( error, acc ) { - if ( error ) { - throw error; - } - console.log( acc.count ); -} - -function read( acc, file, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( file, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( null, acc ); - } - acc.count += 1; - next( null, acc ); - } -} - -var acc = { - 'count': 0 -}; -reduceRightAsync( files, acc, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 28e0a36..f6cba5d 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..97d9f26 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as c}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";function m(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}var d=m(Object.freeze({__proto__:null,default:()=>()=>{}}))("reduce-right-async:limit");function f(e,m){var f,u,p;if(f={},arguments.length>1){if(u=function(e,t){return n(t)?(o(t,"thisArg")&&(e.thisArg=t.thisArg),o(t,"series")&&(e.series=t.series,!l(e.series))?new TypeError(r("1RZ2o","series",e.series)):o(t,"limit")&&(e.limit=t.limit,!c(e.limit))?new TypeError(r("1RZ3P","limit",e.limit)):null):new TypeError(r("1RZ2V",t))}(f,e),u)throw u;p=m}else p=e;if(!t(p))throw new TypeError(r("1RZ3q",p));return void 0===f.series&&void 0===f.limit&&(f.series=!0),f.series?f.limit=1:f.limit||(f.limit=s),function(e,s,n){if(!i(e))throw new TypeError(r("1RZAh",e));if(!t(n))throw new TypeError(r("1RZ3q",n));return function(e,t,i,r,s){var n,o,l,c,m,f;if(c=e.length,d("Collection length: %d",c),0===c)return d("Finished processing a collection."),s(null,t);for(l=c0&&u();function u(){function s(e,i){if(!o){if(e)return o=!0,p(e);d("Accumulator: %s",JSON.stringify(i)),t=i,p()}}d("Collection element %d: %s.",m-=1,JSON.stringify(e[m])),3===r.length?r.call(i.thisArg,t,e[m],s):4===r.length?r.call(i.thisArg,t,e[m],m,s):r.call(i.thisArg,t,e[m],m,e,s)}function p(e){return e?(d("Encountered an error: %s",e.message),s(e)):(d("Processed %d of %d collection elements.",n+=1,c),m>0?u():n===c?(d("Finished processing a collection."),s(null,t)):void 0)}}(e,s,f,p,(function(e,t){if(e)return n(e);n(null,t)}))}}function u(e,t,i,r,s){if(arguments.length<5)return f(i)(e,t,r);f(i,r)(e,t,s)}e(u,"factory",f);export{u as default,f as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..e11f2cb --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/limit.js","../lib/factory.js","../lib/validate.js","../lib/main.js","../lib/index.js"],"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 logger = require( 'debug' );\n\n\n// VARIABLES //\n\nvar debug = logger( 'reduce-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a 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 {*} acc - initial value\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} fcn - function to invoke\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, acc, opts, fcn, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\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, acc );\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', fcn.length );\n\n\tcount = 0;\n\tidx = len;\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\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 ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], cb );\n\t\t} else if ( fcn.length === 4 ) {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes processing a collection element.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [result] - accumulation result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, result ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of collection elements:\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( error ) {\n\t\t\t\tflg = true;\n\t\t\t\treturn clbk( error );\n\t\t\t}\n\t\t\tdebug( 'Accumulator: %s', JSON.stringify( result ) );\n\t\t\tacc = result;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @returns {void}\n\t*/\n\tfunction clbk( error ) {\n\t\tif ( error ) {\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\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, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport PINF from '@stdlib/constants-float64-pinf';\nimport validate from './validate.js';\nimport limit from './limit.js';\n\n\n// MAIN //\n\n/**\n* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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=true] - 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} fcn - 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 provided function once for each element in a collection\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( acc, file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error, data ) {\n* if ( error ) {\n* return next( null, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var opts = {\n* 'series': false\n* };\n*\n* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently:\n* var reduceRightAsync = factory( opts, read );\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 errors:\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* // Run `read` for each element in `files`:\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, done );\n*/\nfunction factory( options, fcn ) {\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 = fcn;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RZ3q', f ) );\n\t}\n\tif ( opts.series === void 0 && opts.limit === void 0 ) {\n\t\topts.series = true;\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 reduceRightAsync;\n\n\t/**\n\t* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {*} initial - initial value\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction reduceRightAsync( collection, initial, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( '1RZAh', collection ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RZ3q', done ) );\n\t\t}\n\t\treturn limit( collection, initial, 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 {*} [acc] - accumulated value\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, acc ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, acc );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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( '1RZ2V', 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( '1RZ2o', '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( '1RZ3P', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default 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\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* ## Notes\n*\n* - If a provided 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 {*} initial - initial value\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=true] - 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} fcn - 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} 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* import readFile from '@stdlib/fs-read-file';\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\nfunction reduceRightAsync( collection, initial, options, fcn, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, initial, fcn );\n\t}\n\tfactory( options, fcn )( collection, initial, done );\n}\n\n\n// EXPORTS //\n\nexport default reduceRightAsync;\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* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.\n*\n* @module @stdlib/utils-async-reduce-right\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import reduceRightAsync from '@stdlib/utils-async-reduce-right';\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, acc ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( acc.count );\n* }\n*\n* function read( acc, 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, acc );\n* }\n* acc.count += 1;\n* next( null, acc );\n* }\n* }\n*\n* var acc = {\n* 'count': 0\n* };\n* reduceRightAsync( files, acc, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["debug","logger","factory","options","fcn","opts","err","f","arguments","length","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","validate","isFunction","PINF","collection","initial","done","isCollection","acc","count","flg","lim","len","idx","i","next","cb","error","result","clbk","JSON","stringify","call","message","reduceRightAsync","setReadOnly","main"],"mappings":";;81CA2BIA,uDAAQC,CAAQ,4BCoEpB,SAASC,EAASC,EAASC,GAC1B,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAA,EACFG,UAAUC,OAAS,EAAI,CAE3B,GADAH,EChDF,SAAmBD,EAAMF,GACxB,OAAMO,EAAUP,IAGXQ,EAAYR,EAAS,aACzBE,EAAKO,QAAUT,EAAQS,SAEnBD,EAAYR,EAAS,YACzBE,EAAKQ,OAASV,EAAQU,QAChBC,EAAWT,EAAKQ,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUX,EAAKQ,SAGnDF,EAAYR,EAAS,WACzBE,EAAKY,MAAQd,EAAQc,OACfC,EAAmBb,EAAKY,QACtB,IAAIF,UAAWC,EAAQ,QAAS,QAASX,EAAKY,QAGhD,MAjBC,IAAIF,UAAWC,EAAQ,QAASb,GAkBzC,CD4BQgB,CAAUd,EAAMF,GACjBG,EACJ,MAAMA,EAEPC,EAAIH,CACN,MACEG,EAAIJ,EAEL,IAAMiB,EAAYb,GACjB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAUvC,YARqB,IAAhBF,EAAKQ,aAAoC,IAAfR,EAAKY,QACnCZ,EAAKQ,QAAS,GAEVR,EAAKQ,OACTR,EAAKY,MAAQ,EACDZ,EAAKY,QACjBZ,EAAKY,MAAQI,GAed,SAA2BC,EAAYC,EAASC,GAC/C,IAAMC,EAAcH,GACnB,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,IAAMF,EAAYI,GACjB,MAAM,IAAIT,UAAWC,EAAQ,QAASQ,IAEvC,ODhGF,SAAgBF,EAAYI,EAAKrB,EAAMD,EAAKoB,GAC3C,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAF,EAAMR,EAAWb,OACjBT,EAAO,wBAAyB8B,GAEnB,IAARA,EAEJ,OADA9B,EAAO,qCACAwB,EAAM,KAAME,GAYpB,IATCG,EADIC,EAAMzB,EAAKY,MACTa,EAEAzB,EAAKY,MAEZjB,EAAO,wBAAyB6B,GAChC7B,EAAO,0BAA2BI,EAAIK,QAEtCkB,EAAQ,EACRI,EAAMD,EACAE,EAAI,EAAGA,EAAIH,EAAKG,IAEhBD,EAAM,GACVE,IAQF,SAASA,IAkBR,SAASC,EAAIC,EAAOC,GACnB,IAAKR,EAAL,CAIA,GAAKO,EAEJ,OADAP,GAAM,EACCS,EAAMF,GAEdnC,EAAO,kBAAmBsC,KAAKC,UAAWH,IAC1CV,EAAMU,EACNC,GAPC,CAQD,CA5BDrC,EAAO,6BADP+B,GAAO,EACmCO,KAAKC,UAAWjB,EAAYS,KAClD,IAAf3B,EAAIK,OACRL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOG,GACtB,IAAf9B,EAAIK,OACfL,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKG,GAErD9B,EAAIoC,KAAMnC,EAAKO,QAASc,EAAKJ,EAAYS,GAAOA,EAAKT,EAAYY,EAuBlE,CASD,SAASG,EAAMF,GACd,OAAKA,GACJnC,EAAO,2BAA4BmC,EAAMM,SAClCjB,EAAMW,KAGdnC,EAAO,0CADP2B,GAAS,EACgDG,GACpDC,EAAM,EACHE,IAEHN,IAAUG,GACd9B,EAAO,qCACAwB,EAAM,KAAME,SAFpB,EAIA,CACF,CCKST,CAAOK,EAAYC,EAASlB,EAAME,GAUzC,SAAe4B,EAAOT,GACrB,GAAKS,EACJ,OAAOX,EAAMW,GAEdX,EAAM,KAAME,EACZ,GACD,CACF,CE1EA,SAASgB,EAAkBpB,EAAYC,EAASpB,EAASC,EAAKoB,GAC7D,GAAKhB,UAAUC,OAAS,EACvB,OAAOP,EAASC,EAATD,CAAoBoB,EAAYC,EAASnB,GAEjDF,EAASC,EAASC,EAAlBF,CAAyBoB,EAAYC,EAASC,EAC/C,CClBAmB,EAAAC,EAAA,UAAA1C"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index e107128..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,164 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var PINF = require( '@stdlib/constants-float64-pinf' ); -var validate = require( './validate.js' ); -var limit = require( './limit.js' ); - - -// MAIN // - -/** -* Returns a function to apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} last argument must be a function -* @returns {Function} function which invokes the provided function once for each element in a collection -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error, data ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var opts = { -* 'series': false -* }; -* -* // Create a `reduceRightAsync` function which invokes `read` for each collection element concurrently: -* var reduceRightAsync = factory( opts, read ); -* -* // Create a collection over which to iterate: -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* // Define a callback which handles errors: -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* // Run `read` for each element in `files`: -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, done ); -*/ -function factory( options, fcn ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = fcn; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '1RZ3q', f ) ); - } - if ( opts.series === void 0 && opts.limit === void 0 ) { - opts.series = true; - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return reduceRightAsync; - - /** - * Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. - * - * @private - * @param {Collection} collection - input collection - * @param {*} initial - initial value - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be a collection - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function reduceRightAsync( collection, initial, done ) { - if ( !isCollection( collection ) ) { - throw new TypeError( format( '1RZAh', collection ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '1RZ3q', done ) ); - } - return limit( collection, initial, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {*} [acc] - accumulated value - * @returns {void} - */ - function clbk( error, acc ) { - if ( error ) { - return done( error ); - } - done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ae657ff..0000000 --- a/lib/index.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* @module @stdlib/utils-async-reduce-right -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var reduceRightAsync = require( '@stdlib/utils-async-reduce-right' ); -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/limit.js b/lib/limit.js deleted file mode 100644 index cdb60af..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); - - -// VARIABLES // - -var debug = logger( 'reduce-right-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each element in a collection, limiting the number of concurrently pending functions and iterating from right to left. -* -* @private -* @param {Collection} collection - input collection -* @param {*} acc - initial value -* @param {Options} opts - function options -* @param {*} [opts.thisArg] - execution context -* @param {PositiveInteger} [opts.limit] - maximum number of pending function invocations -* @param {Function} fcn - function to invoke -* @param {Callback} done - function to invoke upon completion or upon encountering an error -* @returns {void} -*/ -function limit( collection, acc, opts, fcn, done ) { - var count; - var flg; - var lim; - var len; - var idx; - var i; - - len = collection.length; - debug( 'Collection length: %d', len ); - - if ( len === 0 ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - count = 0; - idx = len; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all collection elements... - if ( idx > 0 ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next element in a collection. - * - * @private - */ - function next() { - idx -= 1; - debug( 'Collection element %d: %s.', idx, JSON.stringify( collection[ idx ] ) ); - if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], cb ); - } else if ( fcn.length === 4 ) { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, cb ); - } else { - fcn.call( opts.thisArg, acc, collection[ idx ], idx, collection, cb ); // eslint-disable-line max-len - } - /** - * Callback invoked once a provided function finishes processing a collection element. - * - * @private - * @param {*} [error] - error - * @param {*} [result] - accumulation result - * @returns {void} - */ - function cb( error, result ) { - if ( flg ) { - // Prevent further processing of collection elements: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Accumulator: %s', JSON.stringify( result ) ); - acc = result; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next collection element. - * - * @private - * @param {*} [error] - error - * @returns {void} - */ - function clbk( error ) { - if ( error ) { - debug( 'Encountered an error: %s', error.message ); - return done( error ); - } - count += 1; - debug( 'Processed %d of %d collection elements.', count, len ); - if ( idx > 0 ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing a collection.' ); - return done( null, acc ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index c8b0d0f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Applies a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - 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`). -* -* @param {Collection} collection - input collection -* @param {*} initial - initial value -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @param {boolean} [options.series=true] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection -* @param {Function} fcn - function to invoke for each element in a collection -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be a collection -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} second-to-last argument must be a function -* @throws {TypeError} last argument must be a function -* @returns {void} -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function done( error, acc ) { -* if ( error ) { -* throw error; -* } -* console.log( acc.count ); -* } -* -* function read( acc, file, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( file, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, acc ); -* } -* acc.count += 1; -* next( null, acc ); -* } -* } -* -* var files = [ -* './beep.js', -* './boop.js' -* ]; -* var acc = { -* 'count': 0 -* }; -* reduceRightAsync( files, acc, read, done ); -*/ -function reduceRightAsync( collection, initial, options, fcn, done ) { - if ( arguments.length < 5 ) { - return factory( options )( collection, initial, fcn ); - } - factory( options, fcn )( collection, initial, done ); -} - - -// EXPORTS // - -module.exports = reduceRightAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 0c666fe..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {*} [options.thisArg] - execution context -* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time -* @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 -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'thisArg': {}, -* 'series': false, -* 'limit': 10 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '1RZ2V', options ) ); - } - if ( hasOwnProp( options, 'thisArg' ) ) { - opts.thisArg = options.thisArg; - } - if ( hasOwnProp( options, 'series' ) ) { - opts.series = options.series; - if ( !isBoolean( opts.series ) ) { - return new TypeError( format( '1RZ2o', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '1RZ3P', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index fa2e069..563c57c 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Apply a function against an accumulator and each element in a collection and return the accumulated result, iterating from right to left.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,44 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-collection": "^0.2.2", - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/assert-is-positive-integer": "^0.2.2", - "@stdlib/constants-float64-pinf": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "debug": "^2.6.9", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/constants-float64-eps": "^0.2.2", - "@stdlib/fs-read-file": "^0.2.2", - "@stdlib/utils-noop": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..69bcdc8 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 8244931..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1095 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( {}, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value, next ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - factory( opts, next ); - }; - } -}); - -tape( 'the function returns a function (no options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( acc, value, clbk ) { - clbk( null, acc ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided a collection (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a collection (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var reduceRightAsync; - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - reduceRightAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (1 argument)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function returns a function which invokes a provided function with five arguments (2 arguments)', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with five arguments', function test( t ) { - var reduceRightAsync; - var values; - var arr; - var acc; - var i; - var j; - - reduceRightAsync = factory( fcn ); - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, done ); - - function fcn() { - var value; - var next; - var acc; - var k; - - acc = arguments[ 0 ]; - value = arguments[ 1 ]; - k = arguments[ 2 ]; - next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( k, i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns accumulated result' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the returned function supports processing collection elements sequentially', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements concurrently', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 100, 250, 300 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function for processing collection elements sequentially (limit = 1)', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 300, 250, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of collection elements which are processed at any one time', function test( t ) { - var reduceRightAsync; - var expected; - var count; - var opts; - var arr; - - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 100, 250, 300 ]; - expected = [ 250, 300, 100 ]; - count = -1; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( value, expected[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': true - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'limit': 2 - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 250, 100, 300 ]; - count = 0; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var reduceRightAsync; - var count; - var opts; - var arr; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 500, 500, 500 ]; - count = 0; - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var reduceRightAsync; - var arr; - - reduceRightAsync = factory( fcn ); - arr = []; - - reduceRightAsync( arr, 0, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the returned function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var reduceRightAsync; - var obj; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = []; - obj = {}; - reduceRightAsync( arr, obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var reduceRightAsync; - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - reduceRightAsync = factory( opts, fcn ); - - arr = [ 3, 2, 1 ]; - i = 0; - - reduceRightAsync( arr, {}, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, acc ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the returned function does not skip empty elements', function test( t ) { - var reduceRightAsync; - var expected; - var arr; - - reduceRightAsync = factory( fcn ); - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index f273a40..0000000 --- a/test/test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof reduceRightAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 1893240..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1035 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var reduceRightAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof reduceRightAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a collection', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( value, 0, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each collection element (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (no options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, {}, next, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, 0 ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - reduceRightAsync( [ 1, 2, 3 ], 0, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( acc, value, clbk ) { - clbk( null, acc ); - } - - values = [ - '5', - -5, - 3.14, - 0, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'limit': value - }; - reduceRightAsync( [ 1, 2, 3 ], 0, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, next ) { - i += 1; - t.strictEqual( value, values[ i ], 'provides expected value' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each element in a collection (acc,value,index,collection,next)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, collection, next ) { - i -= 1; - j += 1; - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( index, i, 'provides expected index' ); - t.strictEqual( collection, arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (1 argument)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc ) { - var value = arguments[ 1 ]; - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 3 arguments, the function invokes a provided function with five arguments (2 arguments)', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value ) { - var next = arguments[ 4 ]; - - i -= 1; - j += 1; - - t.strictEqual( value, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, value ); - - function onTimeout() { - acc.sum += value; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with five arguments', function test( t ) { - var values; - var arr; - var acc; - var i; - var j; - - arr = [ 3, 2, 1 ]; - values = [ 1, 2, 3 ]; - i = arr.length; - j = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn() { - var next; - var acc; - var v; - - next = arguments[ 4 ]; - acc = arguments[ 0 ]; - v = arguments[ 1 ]; - - i -= 1; - j += 1; - - t.strictEqual( v, values[ j ], 'provides expected value' ); - t.strictEqual( arguments[ 2 ], i, 'provides expected index' ); - t.strictEqual( arguments[ 3 ], arr, 'provides input collection' ); - - setTimeout( onTimeout, v ); - - function onTimeout() { - acc.sum += v; - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 6, 'returns expected result' ); - t.end(); - } -}); - -tape( 'by default, the function processes collection elements sequentially', function test( t ) { - var values; - var count; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - reduceRightAsync( arr, acc, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements concurrently', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 100, 250, 300 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': true - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports processing collection elements sequentially (limit = 1)', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 300, 250, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 1 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of collection elements which are processed at any one time', function test( t ) { - var values; - var count; - var opts; - var arr; - var acc; - - arr = [ 100, 250, 300 ]; - values = [ 250, 300, 100 ]; - count = -1; - - acc = { - 'sum': 0 - }; - opts = { - 'series': false, - 'limit': 2 - }; - reduceRightAsync( arr, acc, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - acc.sum += value; - t.strictEqual( value, values[ count ], 'provides expected value' ); - next( null, acc ); - } - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc.sum, 650, 'returns expected result' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var arr; - var ctx; - - arr = [ 3, 2, 1 ]; - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( ctx.count, 3, 'updated provided context' ); - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 3, 2, 1 ]; - opts = { - 'series': true - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 1, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 250, 100, 300 ]; - opts = { - 'limit': 2 - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 2, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - if ( index === 1 ) { - return next( new Error( 'beep' ) ); - } - next( null, acc ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if an error is encountered while processing a collection element, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var opts; - var arr; - - arr = [ 500, 500, 500 ]; - opts = { - 'series': false - }; - count = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - - function fcn( acc, value, index, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - function done( error ) { - t.strictEqual( count, 3, 'suspends execution' ); - if ( error ) { - t.pass( error.message ); - } else { - t.fail( 'did not return an error' ); - } - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result', function test( t ) { - var arr = []; - reduceRightAsync( arr, 0, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, 0, 'returns initial value' ); - t.end(); - } -}); - -tape( 'if provided an empty collection, the function never invokes a provided function and returns the initial value as the accumulated result (object)', function test( t ) { - var arr = []; - var obj = {}; - - reduceRightAsync( arr, obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, acc ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( acc, obj, 'returns initial value' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var opts; - var arr; - var i; - - opts = { - 'series': false - }; - arr = [ 3, 2, 1 ]; - i = 0; - reduceRightAsync( arr, {}, opts, fcn, done ); - i = 1; - - function fcn( acc, value, next ) { - next( null, value ); - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.strictEqual( i, 0, 'releases the zalgo' ); - t.end(); - } -}); - -tape( 'the function does not skip empty elements', function test( t ) { - var expected; - var arr; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ 1, void 0, void 0, 4 ]; - - reduceRightAsync( arr, {}, fcn, done ); - - function fcn( acc, value, index, next ) { - t.strictEqual( value, expected[ index ], 'provides expected value' ); - setTimeout( onTimeout, 0 ); - - function onTimeout() { - return next( null, acc ); - } - } - - function done( error ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.end(); - } -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 7660838..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,181 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `limit` option which is not a positive integer', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - -5, - 0, - 3.14, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'limit': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `series` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'series': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function accepts any value for the `thisArg` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'thisArg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err, null, 'returns null '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'thisArg': {}, - 'series': false, - 'limit': 10 - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -});